@kabmo-labs/kabmo 0.53.2 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +538 -527
- package/dist/client/static/js/{Body-vaa10tcd.js → Body-a4dwe3hh.js} +1 -1
- package/dist/client/static/js/{CsvGrid-wabx4e6w.js → CsvGrid-ppj80brw.js} +1 -1
- package/dist/client/static/js/{DocxView-22b3mhh5.js → DocxView-ef0bd2pg.js} +1 -1
- package/dist/client/static/js/{DrawioView-e02qhkp2.js → DrawioView-44tpkzbd.js} +1 -1
- package/dist/client/static/js/{HtmlPreview-q7hwcf4s.js → HtmlPreview-w654aykz.js} +1 -1
- package/dist/client/static/js/{ImageView-fxb60ge7.js → ImageView-kg0skt5s.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-cey5agsf.js → LayoutWrapper-qepkrtd8.js} +2 -2
- package/dist/client/static/js/MergeDiffView-n2h8vv0j.js +1 -0
- package/dist/client/static/js/{Modal-e4yq7p5f.js → Modal-8d299emm.js} +17 -17
- package/dist/client/static/js/{PdfView-pf3angsq.js → PdfView-eq7fnqa2.js} +1 -1
- package/dist/client/static/js/{SessionsView-mcvhpx0b.js → SessionsView-tedh2es3.js} +1 -1
- package/dist/client/static/js/{SheetView-5ha5vvsr.js → SheetView-5xm33kgk.js} +1 -1
- package/dist/client/static/js/{SvgPreview-45wqjw0b.js → SvgPreview-tp1m8r4t.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-gnf6krbs.js → abnfDiagram-O67JEVCF-xppr9jf1.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-00fd0wsg.js → architectureDiagram-NJMV4G6O-s23e6vtk.js} +1 -1
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-9c2sm96a.js → blockDiagram-BEXU5L5S-7ws8yq9e.js} +1 -1
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-pemygn0s.js → c4Diagram-YGBWAQC7-517yhfzj.js} +1 -1
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-h7r3sx3s.js → classDiagram-v2-NBCMYWYE-tcad3rst.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-krx9crwv.js → cose-bilkent-JH36ORCC-a76vf82p.js} +1 -1
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-5rp2btew.js → cynefinDiagram-VND7K2PF-9kety453.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-q57cnz52.js → dagre-6A5THRUB-6g6gsp6b.js} +1 -1
- package/dist/client/static/js/{diagram-22UHCM2B-0bptn06k.js → diagram-22UHCM2B-ngj4fyg3.js} +1 -1
- package/dist/client/static/js/{diagram-3UASUU5V-60snxawz.js → diagram-3UASUU5V-xw2m99qa.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-bb0kewfp.js → diagram-ATOU4E4O-hz3bd083.js} +2 -2
- package/dist/client/static/js/{diagram-CDSNMT55-3cdkns0z.js → diagram-CDSNMT55-vfhtemve.js} +3 -3
- package/dist/client/static/js/{diagram-MLGK6HIB-03mbhzeq.js → diagram-MLGK6HIB-22cjvj5g.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-bcvzqqf4.js → diagram-MPIPVDR6-xv8fsecp.js} +2 -2
- package/dist/client/static/js/{dockerfile-7kqkk4tz.js → dockerfile-491tyqmj.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-sg6kwnbx.js → ebnfDiagram-ZINNZB2B-m6mkn986.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-5b8v0sdv.js → elk-276RUBZZ-jccw706n.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-xbs156j5.js → erDiagram-OPXOYQCR-rxk86jsf.js} +1 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-aegwx04w.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-4p7pfk6c.js → ganttDiagram-FUAMR5RP-veweech7.js} +1 -1
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-3xqwr9pf.js → gitGraphDiagram-X574FWY7-7dyqcj8r.js} +2 -2
- package/dist/client/static/js/{index-p75b7phb.js → index-088gwjbz.js} +1 -1
- package/dist/client/static/js/{index-5qtnmn76.js → index-0ak5wdz1.js} +1 -1
- package/dist/client/static/js/{index-pak6t03c.js → index-0qmpqtp2.js} +1 -1
- package/dist/client/static/js/{index-26a4afcr.js → index-0xh8402w.js} +1 -1
- package/dist/client/static/js/{index-yf5a6t3p.js → index-2asa0faw.js} +1 -1
- package/dist/client/static/js/{index-gzz6snng.js → index-2cfw7wem.js} +1 -1
- package/dist/client/static/js/{index-e2esj214.js → index-39mr4tym.js} +1 -1
- package/dist/client/static/js/{index-hp3s5r3g.js → index-3x88fxzj.js} +1 -1
- package/dist/client/static/js/{index-trrmbq0h.js → index-4m94cbms.js} +1 -1
- package/dist/client/static/js/{index-rtpg4t84.js → index-5701gj1f.js} +1 -1
- package/dist/client/static/js/{index-pdkt3r4r.js → index-60fjqzdw.js} +1 -1
- package/dist/client/static/js/{index-mtjbp5ga.js → index-637my5h0.js} +1 -1
- package/dist/client/static/js/{index-c8ta3k4g.js → index-7ckzdf4r.js} +158 -156
- package/dist/client/static/js/{index-1d8ff4t7.js → index-7ehep28z.js} +2 -2
- package/dist/client/static/js/{index-hwq7zgqd.js → index-bfy437re.js} +1 -1
- package/dist/client/static/js/{index-zc3snsr9.js → index-bhst1c2x.js} +1 -1
- package/dist/client/static/js/{index-nnhs52db.js → index-cz80n8yc.js} +1 -1
- package/dist/client/static/js/{index-ayx3q8t9.js → index-d9dz0wt0.js} +1 -1
- package/dist/client/static/js/{index-3bmn5cc5.js → index-dg714jam.js} +1 -1
- package/dist/client/static/js/{index-z7gd7nvb.js → index-e6tjaccf.js} +1 -1
- package/dist/client/static/js/{index-vwxt5ss9.js → index-gsw1zh30.js} +1 -1
- package/dist/client/static/js/{index-x0y2c61e.js → index-j0qt8gaj.js} +1 -1
- package/dist/client/static/js/{index-45vcpqp9.js → index-kfcpkx7h.js} +1 -1
- package/dist/client/static/js/{index-cy6ceab8.js → index-na95tr1k.js} +1 -1
- package/dist/client/static/js/{index-ng3e6k6x.js → index-nzjc24v9.js} +1 -1
- package/dist/client/static/js/{index-3amzzsdk.js → index-pqmvhqmj.js} +11 -11
- package/dist/client/static/js/{index-0btbxkxf.js → index-r51fqzb5.js} +1 -1
- package/dist/client/static/js/{index-cj8v7b50.js → index-sx5x2q80.js} +1 -1
- package/dist/client/static/js/{index-qj9tcz44.js → index-tk1vr8q2.js} +1 -1
- package/dist/client/static/js/{index-j9t5xc3y.js → index-trpn9gxs.js} +1 -1
- package/dist/client/static/js/{index-1regq9wd.js → index-twjq786a.js} +1 -1
- package/dist/client/static/js/{index-xqkcx4az.js → index-wa234c7k.js} +1 -1
- package/dist/client/static/js/{index-mgs5nscx.js → index-wp7tsava.js} +1 -1
- package/dist/client/static/js/{index-nmhwjwmt.js → index-wvqwzgpx.js} +1 -1
- package/dist/client/static/js/{index-jg6ecfc7.js → index-xbvjpa60.js} +2 -2
- package/dist/client/static/js/{index-jf8zcg99.js → index-xm3691yp.js} +4 -4
- package/dist/client/static/js/{index-cysdvwqw.js → index-xq78fj64.js} +1 -1
- package/dist/client/static/js/{index-ryww3xxj.js → index-zjc8yfbe.js} +1 -1
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-c362sv3t.js → infoDiagram-VRGFBTTK-ksz9cvq3.js} +1 -1
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-yc8ts8wj.js → ishikawaDiagram-OU5B5YK6-g8symmrp.js} +1 -1
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-178c75fy.js → journeyDiagram-ZHPQQLJL-qs2e3hdf.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-w6g3n001.js → kanban-definition-PNTS6WVX-pzef80sz.js} +1 -1
- package/dist/client/static/js/{mermaid.core-vcdgn378.js → mermaid.core-chfcvkkc.js} +3 -3
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-t9e8arca.js → mindmap-definition-NLK3R4M7-sds2e243.js} +1 -1
- package/dist/client/static/js/one-dark-pro-5fvhpb1t.js +1 -0
- package/dist/client/static/js/one-light-pwj40vbr.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-nehn0x9n.js → pegDiagram-GJSIUBJH-m8199cy0.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-p1t3ctd4.js → pieDiagram-5QR66LMP-wqz5k5w6.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-614rtbfe.js → quadrantDiagram-O4NWA36T-rjszd8an.js} +1 -1
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-2vpr6pw8.js → railroadDiagram-XR7U4H2S-qv0be7dh.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b91s5q3p.js → requirementDiagram-PLB6GJNP-b87kqbr7.js} +1 -1
- package/dist/client/static/js/{rust-jj206pb7.js → rust-m7ma3tq9.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-4101kt9r.js → sankeyDiagram-IPEJSGJF-dh5we479.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-yq0cxg8c.js → sequenceDiagram-PO4LG4MO-e6fg0x45.js} +1 -1
- package/dist/client/static/js/{sizeCapture-INFHLROL-jkvq39vz.js → sizeCapture-INFHLROL-mam6cagq.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-y0h7w5rw.js → stateDiagram-v2-GCMORJYK-htwar22v.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-1y073wzx.js → swimlanes-2SLR337P-5g26cnkr.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-8ahz3c68.js → swimlanesDiagram-TC7HE7FX-rseba3zs.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-yjb0g0ys.js → timeline-definition-EJHVYXUP-5km8n8mj.js} +1 -1
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-8xjkxrkv.js → usecaseDiagram-POWQR4AR-0vt6ms5g.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-18wjbwtg.js → vennDiagram-UO4OBE2U-k425105a.js} +2 -2
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-xqrfsrwp.js → wardleyDiagram-VNRHLVJA-s0gd4jg1.js} +2 -2
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-azygghkz.js → xychartDiagram-PMCCYNJV-2nrdzp7p.js} +2 -2
- package/package.json +5 -5
- package/src/client/App.tsx +4 -0
- package/src/client/bootstrap.d.ts +11 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AgentAdmin.test.tsx +67 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AgentAdmin.tsx +89 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Mcp.test.tsx +91 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Mcp.tsx +8 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +9 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +16 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/WebSearch.test.tsx +59 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/WebSearch.tsx +11 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/agent-admin-rows.test.ts +119 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/agent-admin-rows.ts +174 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/task-rows.ts +14 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +22 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +14 -0
- package/src/client/data/settings/omp-schema.json +455 -165
- package/src/client/hooks/shell/last-opened-session.test.ts +166 -0
- package/src/client/hooks/shell/last-opened-session.ts +74 -0
- package/src/client/lib/router/open-session.test.ts +8 -0
- package/src/client/lib/router/open-session.ts +9 -4
- package/src/client/main.tsx +7 -0
- package/src/server/lib/db/schema.ts +10 -0
- package/src/server/lib/sessions/last-opened-client.server.ts +86 -0
- package/src/server/lib/sessions/last-opened-client.test.ts +91 -0
- package/src/server/lib/sessions/last-opened.server.test.ts +127 -0
- package/src/server/lib/sessions/last-opened.server.ts +129 -0
- package/src/server/plugins/ssr.ts +40 -17
- package/src/server/routes/fs/raw.test.ts +33 -0
- package/src/server/routes/fs/raw.ts +31 -11
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/last-opened.test.ts +139 -0
- package/src/server/routes/sessions/last-opened.ts +66 -0
- package/src/shared/lib/chat/timeline/tool-phrases.test.ts +4 -0
- package/src/shared/lib/chat/timeline/tool-phrases.ts +2 -0
- package/src/shared/lib/models/provider/glyph.test.ts +13 -11
- package/src/shared/lib/models/provider/glyph.ts +1 -0
- package/src/shared/lib/models/provider/label.ts +3 -0
- package/src/shared/lib/omp/config/schema-releases-19-3.test.ts +64 -0
- package/src/shared/lib/omp/config/schema-releases.test.ts +21 -4
- package/src/shared/lib/omp/session/wait-idle.test.ts +12 -2
- package/src/shared/lib/omp/session/wait-idle.ts +11 -6
- package/dist/client/static/js/MergeDiffView-1z9mwf73.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-sasgvf55.js +0 -1
- package/dist/client/static/js/one-dark-pro-17hh3q12.js +0 -1
- package/dist/client/static/js/one-light-cntgvscy.js +0 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Cold-start session continuity, from the page's side.
|
|
8
|
+
*
|
|
9
|
+
* The two halves are invisible when wrong: a restore that ignores the shell
|
|
10
|
+
* leaves every relaunch on the empty workspace, and a restore that overrides an
|
|
11
|
+
* explicit deep link opens the wrong chat. The recorder's failure mode is the
|
|
12
|
+
* same shape one launch later — the app remembers a session the user never
|
|
13
|
+
* opened, or loses the one they did.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { h, render } from 'preact';
|
|
19
|
+
import { act } from 'preact/test-utils';
|
|
20
|
+
|
|
21
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
22
|
+
import {
|
|
23
|
+
restoreLastOpenedSession,
|
|
24
|
+
useSessionOpenRecorder,
|
|
25
|
+
} from '@/client/hooks/shell/last-opened-session';
|
|
26
|
+
|
|
27
|
+
const nativeFetch = globalThis.fetch;
|
|
28
|
+
let container: HTMLElement | undefined;
|
|
29
|
+
let requests: string[];
|
|
30
|
+
|
|
31
|
+
function pointAt(search: string): void {
|
|
32
|
+
window.history.replaceState(null, '', `/${search}`);
|
|
33
|
+
window.dispatchEvent(new Event('popstate'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function asDesktopShell(): void {
|
|
37
|
+
(window as unknown as Record<string, unknown>).__kabmoDesktop = {
|
|
38
|
+
platform: 'macos',
|
|
39
|
+
shellVersion: '0.0.0',
|
|
40
|
+
overlayTitlebar: true,
|
|
41
|
+
};
|
|
42
|
+
// The desktop trio installs BOTH, and `hasShellBridge` asks the transport —
|
|
43
|
+
// the identity alone is what draws the titlebar, not what answers commands.
|
|
44
|
+
(window as unknown as Record<string, unknown>).__kabmoCall = async () => null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function asBrowser(): void {
|
|
48
|
+
const win = window as unknown as Record<string, unknown>;
|
|
49
|
+
delete win.__kabmoDesktop;
|
|
50
|
+
delete win.kabmoHost;
|
|
51
|
+
delete win.webkit;
|
|
52
|
+
delete win.__kabmoCall;
|
|
53
|
+
delete win.__kabmoShellHost;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Probe({ enabled }: { enabled: boolean }) {
|
|
57
|
+
useSessionOpenRecorder(enabled);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
beforeAll(() => {
|
|
62
|
+
installDomGlobals(new Window({ url: 'http://localhost/' }));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
pointAt('');
|
|
67
|
+
asBrowser();
|
|
68
|
+
requests = [];
|
|
69
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
70
|
+
requests.push(String(input));
|
|
71
|
+
return new Response(null, { status: 200 });
|
|
72
|
+
}) as unknown as typeof fetch;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
if (container) {
|
|
77
|
+
render(null, container);
|
|
78
|
+
container.remove();
|
|
79
|
+
container = undefined;
|
|
80
|
+
}
|
|
81
|
+
asBrowser();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
afterAll(() => {
|
|
85
|
+
pointAt('');
|
|
86
|
+
globalThis.fetch = nativeFetch;
|
|
87
|
+
restoreDomGlobals();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('restoreLastOpenedSession', () => {
|
|
91
|
+
test('a browser keeps its landing', () => {
|
|
92
|
+
expect(restoreLastOpenedSession('session-a')).toBe(false);
|
|
93
|
+
expect(window.location.search).toBe('');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a desktop shell selects the remembered session without adding history', () => {
|
|
97
|
+
asDesktopShell();
|
|
98
|
+
const before = window.history.length;
|
|
99
|
+
expect(restoreLastOpenedSession('session-a')).toBe(true);
|
|
100
|
+
expect(new URL(window.location.href).searchParams.get('sessionId')).toBe('session-a');
|
|
101
|
+
expect(window.history.length).toBe(before);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('a phone shell selects it too', () => {
|
|
105
|
+
(window as unknown as Record<string, unknown>).kabmoHost = { post: () => {} };
|
|
106
|
+
expect(restoreLastOpenedSession('session-b')).toBe(true);
|
|
107
|
+
expect(new URL(window.location.href).searchParams.get('sessionId')).toBe('session-b');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('an explicit deep link wins over the remembered session', () => {
|
|
111
|
+
asDesktopShell();
|
|
112
|
+
pointAt('?sessionId=mine');
|
|
113
|
+
expect(restoreLastOpenedSession('remembered')).toBe(false);
|
|
114
|
+
expect(new URL(window.location.href).searchParams.get('sessionId')).toBe('mine');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('nothing remembered and nothing valid change nothing', () => {
|
|
118
|
+
asDesktopShell();
|
|
119
|
+
expect(restoreLastOpenedSession(null)).toBe(false);
|
|
120
|
+
expect(restoreLastOpenedSession(' ')).toBe(false);
|
|
121
|
+
expect(window.location.search).toBe('');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('useSessionOpenRecorder', () => {
|
|
126
|
+
function mount(enabled: boolean): void {
|
|
127
|
+
container = document.createElement('div');
|
|
128
|
+
document.body.append(container);
|
|
129
|
+
act(() => render(h(Probe, { enabled }), container!));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
test('records the selected session once', async () => {
|
|
133
|
+
pointAt('?sessionId=session-a');
|
|
134
|
+
await act(async () => mount(true));
|
|
135
|
+
expect(requests).toEqual(['/api/sessions/session-a/opened']);
|
|
136
|
+
|
|
137
|
+
// A re-render for the same selection must not repeat the write.
|
|
138
|
+
await act(async () => render(h(Probe, { enabled: true }), container!));
|
|
139
|
+
expect(requests).toHaveLength(1);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('skips a pending chat and records the adopted id', async () => {
|
|
143
|
+
pointAt('?sessionId=new-1761000000000');
|
|
144
|
+
await act(async () => mount(true));
|
|
145
|
+
expect(requests).toEqual([]);
|
|
146
|
+
|
|
147
|
+
await act(async () => pointAt('?sessionId=adopted'));
|
|
148
|
+
expect(requests).toEqual(['/api/sessions/adopted/opened']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('a different session is recorded', async () => {
|
|
152
|
+
pointAt('?sessionId=session-a');
|
|
153
|
+
await act(async () => mount(true));
|
|
154
|
+
await act(async () => pointAt('?sessionId=session-b'));
|
|
155
|
+
expect(requests).toEqual([
|
|
156
|
+
'/api/sessions/session-a/opened',
|
|
157
|
+
'/api/sessions/session-b/opened',
|
|
158
|
+
]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('an unauthenticated screen records nothing', async () => {
|
|
162
|
+
pointAt('?sessionId=session-a');
|
|
163
|
+
await act(async () => mount(false));
|
|
164
|
+
expect(requests).toEqual([]);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Cold-start session continuity for the native shells.
|
|
8
|
+
*
|
|
9
|
+
* A shell opens the console's origin with no query, so the page used to answer
|
|
10
|
+
* with its empty workspace — even though the user had a chat open when they
|
|
11
|
+
* closed the app. Two halves fix that, and they live together because they are
|
|
12
|
+
* one rule seen from each side of the launch:
|
|
13
|
+
*
|
|
14
|
+
* - **Restore** runs BEFORE hydration (`main.tsx`), from the id the server read
|
|
15
|
+
* for this install's `kabmo_client` cookie on the very request that served
|
|
16
|
+
* this document. A `replaceState` there means the first render already names
|
|
17
|
+
* the session: no landing flash, and no history entry for a place the user
|
|
18
|
+
* never chose.
|
|
19
|
+
* - **Record** runs on every URL selection (`App`), so the next launch restores
|
|
20
|
+
* whatever this one left on screen. The write is keyed by the same cookie, so
|
|
21
|
+
* a phone, a desktop shell and a browser each keep their own pointer even
|
|
22
|
+
* when they share one console.
|
|
23
|
+
*
|
|
24
|
+
* Restore is inert outside a shell — `hasShellBridge()` is false in every
|
|
25
|
+
* browser — which is what keeps the browser's landing exactly where it was.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
29
|
+
import { hasShellBridge } from '@/client/lib/shell/transport';
|
|
30
|
+
import { openSessionInUrl } from '@/client/lib/router/open-session';
|
|
31
|
+
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Select the remembered session on a cold start, when this page is inside a
|
|
35
|
+
* native shell and the URL names nothing.
|
|
36
|
+
*
|
|
37
|
+
* Returns whether the URL moved. A deep link that already selected a session
|
|
38
|
+
* wins: the user (or a notification) asked for that one explicitly.
|
|
39
|
+
*/
|
|
40
|
+
export function restoreLastOpenedSession(sessionId: string | null | undefined): boolean {
|
|
41
|
+
if (typeof window === 'undefined') return false;
|
|
42
|
+
if (!hasShellBridge()) return false;
|
|
43
|
+
const id = typeof sessionId === 'string' ? sessionId.trim() : '';
|
|
44
|
+
if (!id) return false;
|
|
45
|
+
if (new URLSearchParams(window.location.search).get('sessionId')) return false;
|
|
46
|
+
return openSessionInUrl(id, { replace: true });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Remember every session the URL selects.
|
|
51
|
+
*
|
|
52
|
+
* `enabled` is the authentication state: a page showing the login screen has no
|
|
53
|
+
* session to remember and its endpoint would answer 401.
|
|
54
|
+
*
|
|
55
|
+
* A pending id (`new-…`, `__new__…`) is skipped because there is no session to
|
|
56
|
+
* reopen yet; the spawn's adoption switches the URL to the real id, which this
|
|
57
|
+
* hook records on its next run. A failed POST is deliberately silent: the
|
|
58
|
+
* previous record still describes a session the user actually opened, and
|
|
59
|
+
* there is no action on this screen to report it against.
|
|
60
|
+
*/
|
|
61
|
+
export function useSessionOpenRecorder(enabled: boolean): void {
|
|
62
|
+
const [searchParams] = useSearchParams();
|
|
63
|
+
const sessionId = searchParams.get('sessionId');
|
|
64
|
+
const sent = useRef<string | null>(null);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!enabled) return;
|
|
68
|
+
const id = sessionId?.trim();
|
|
69
|
+
if (!id || id.startsWith('new-') || id.startsWith('__new__')) return;
|
|
70
|
+
if (sent.current === id) return;
|
|
71
|
+
sent.current = id;
|
|
72
|
+
void fetch(`/api/sessions/${encodeURIComponent(id)}/opened`, { method: 'POST' }).catch(() => {});
|
|
73
|
+
}, [enabled, sessionId]);
|
|
74
|
+
}
|
|
@@ -58,6 +58,14 @@ describe('openSessionInUrl', () => {
|
|
|
58
58
|
expect(events).toBe(1);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
test('a restore replaces the entry instead of adding one', () => {
|
|
62
|
+
go('');
|
|
63
|
+
const before = window.history.length;
|
|
64
|
+
expect(openSessionInUrl('restored', { replace: true })).toBe(true);
|
|
65
|
+
expect(new URL(window.location.href).searchParams.get('sessionId')).toBe('restored');
|
|
66
|
+
expect(window.history.length).toBe(before);
|
|
67
|
+
});
|
|
68
|
+
|
|
61
69
|
test('a blank id changes nothing', () => {
|
|
62
70
|
go('?sessionId=keep');
|
|
63
71
|
expect(openSessionInUrl(' ')).toBe(false);
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* subagent view of a SESSION would hide the transcript the notification named.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
export function openSessionInUrl(sessionId: string): boolean {
|
|
19
|
+
export function openSessionInUrl(sessionId: string, options: { replace?: boolean } = {}): boolean {
|
|
20
20
|
if (typeof window === 'undefined') return false;
|
|
21
21
|
const id = sessionId.trim();
|
|
22
22
|
if (!id) return false;
|
|
@@ -24,9 +24,14 @@ export function openSessionInUrl(sessionId: string): boolean {
|
|
|
24
24
|
const url = new URL(window.location.href);
|
|
25
25
|
url.searchParams.set('sessionId', id);
|
|
26
26
|
url.searchParams.delete('subagent');
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
//
|
|
27
|
+
// `replace` is for a selection the user did not make — the session a native
|
|
28
|
+
// shell restored on launch. A history entry there would make Back return to
|
|
29
|
+
// the empty workspace the restore just replaced, which is not a place the
|
|
30
|
+
// user went.
|
|
31
|
+
if (options.replace) window.history.replaceState(null, '', url);
|
|
32
|
+
else window.history.pushState(null, '', url);
|
|
33
|
+
// Changing history does NOT fire `popstate`, so the search-param store has to
|
|
34
|
+
// be told; otherwise only a reload would show the new selection. A plain Event is
|
|
30
35
|
// enough — the store re-reads `location.search`, which pushState already moved
|
|
31
36
|
// — and it avoids depending on a constructor some environments lack.
|
|
32
37
|
window.dispatchEvent(new Event('popstate'));
|
package/src/client/main.tsx
CHANGED
|
@@ -24,6 +24,7 @@ import { installFileLaunchHandler } from '@/client/lib/launch/file-handlers';
|
|
|
24
24
|
import { installOpenPaths } from '@/client/lib/native/open-paths';
|
|
25
25
|
import { installCommandRunner } from '@/client/lib/native/run-command';
|
|
26
26
|
import { installDeviceFiles } from '@/client/lib/launch/device-files';
|
|
27
|
+
import { restoreLastOpenedSession } from '@/client/hooks/shell/last-opened-session';
|
|
27
28
|
|
|
28
29
|
import '@/client/tailwind.css';
|
|
29
30
|
import '@/client/glass.css';
|
|
@@ -174,6 +175,12 @@ installDeviceFiles();
|
|
|
174
175
|
void bootSyntax().then(() => warmSyntaxTokenizers());
|
|
175
176
|
|
|
176
177
|
if (root) {
|
|
178
|
+
// BEFORE hydration: a shell relaunch with no query in the URL resumes the
|
|
179
|
+
// session this console opened last, so the first render already names it.
|
|
180
|
+
// After `installShellTransport`, which is what lets a phone identify itself,
|
|
181
|
+
// and before `hydrate`, so no component ever paints the empty workspace on
|
|
182
|
+
// the way to the restored chat.
|
|
183
|
+
restoreLastOpenedSession(bootstrap?.lastOpenedSessionId);
|
|
177
184
|
hydrate(
|
|
178
185
|
<App
|
|
179
186
|
initialIsMobile={bootstrap?.initialIsMobile}
|
|
@@ -92,6 +92,16 @@ export async function initSchema(db: DbClient): Promise<void> {
|
|
|
92
92
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
93
93
|
);
|
|
94
94
|
|
|
95
|
+
-- The session each CLIENT opens last — one row per WebView/app install,
|
|
96
|
+
-- identified by the kabmo_client cookie. A native shell restores its own
|
|
97
|
+
-- row on a cold start, so a phone and a desktop pointed at the same console
|
|
98
|
+
-- do not fight over one pointer. See lib/sessions/last-opened.server.ts.
|
|
99
|
+
CREATE TABLE IF NOT EXISTS last_opened_sessions (
|
|
100
|
+
client_id TEXT PRIMARY KEY,
|
|
101
|
+
session_id TEXT NOT NULL,
|
|
102
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
103
|
+
);
|
|
104
|
+
|
|
95
105
|
-- The sidebar's subagent badge, saved per file version so a restart does
|
|
96
106
|
-- not re-derive it by streaming every transcript (see
|
|
97
107
|
-- lib/omp/session/subagent-presence-store). Derived data: deleting the
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The opaque client id that keeps "last opened session" PER INSTALL.
|
|
8
|
+
*
|
|
9
|
+
* A console is one database, but it is not one device: a phone shell, a desktop
|
|
10
|
+
* shell and a browser can all point at the same server, and a single shared
|
|
11
|
+
* pointer made them overwrite each other. Cookie jars are per WebView data
|
|
12
|
+
* store, which is exactly the grain the feature wants — so a random id lives in
|
|
13
|
+
* one cookie and keys the record.
|
|
14
|
+
*
|
|
15
|
+
* The id is not a credential: it names a row in `last_opened_sessions` and
|
|
16
|
+
* nothing else. It is `HttpOnly` because no script needs to read it, and
|
|
17
|
+
* `SameSite=Lax` for the same reason the session cookie uses it — the page's own
|
|
18
|
+
* document navigations must carry it while a cross-site POST must not.
|
|
19
|
+
*
|
|
20
|
+
* The cookie lifetime is deliberately long and independent of the auth session:
|
|
21
|
+
* a device that signs in again is the same install, and "last opened" is about
|
|
22
|
+
* the device, not the login.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { randomUUID } from 'node:crypto';
|
|
26
|
+
import { isSecureRequest } from '@/server/lib/auth/token';
|
|
27
|
+
|
|
28
|
+
export const CLIENT_COOKIE = 'kabmo_client';
|
|
29
|
+
|
|
30
|
+
/** One year. A shell that is not opened for longer gets a fresh pointer. */
|
|
31
|
+
const CLIENT_COOKIE_TTL_SECONDS = 365 * 24 * 60 * 60;
|
|
32
|
+
|
|
33
|
+
/** Generated ids are UUIDs; the cap also bounds a forged cookie's DB key. */
|
|
34
|
+
const CLIENT_ID_PATTERN = /^[A-Za-z0-9_-]{16,64}$/;
|
|
35
|
+
|
|
36
|
+
/** Whether an untrusted cookie value is an id this server minted the shape of. */
|
|
37
|
+
export function isClientId(value: string | null | undefined): value is string {
|
|
38
|
+
return typeof value === 'string' && CLIENT_ID_PATTERN.test(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The client id this request carries, or null when it has none/invalid. */
|
|
42
|
+
export function readClientId(request: Request): string | null {
|
|
43
|
+
const header = request.headers.get('cookie');
|
|
44
|
+
if (!header) return null;
|
|
45
|
+
for (const segment of header.split(';')) {
|
|
46
|
+
const index = segment.indexOf('=');
|
|
47
|
+
if (index === -1) continue;
|
|
48
|
+
if (segment.slice(0, index).trim() !== CLIENT_COOKIE) continue;
|
|
49
|
+
const raw = segment.slice(index + 1).trim();
|
|
50
|
+
if (!raw) return null;
|
|
51
|
+
let value = raw;
|
|
52
|
+
try {
|
|
53
|
+
value = decodeURIComponent(raw);
|
|
54
|
+
} catch {
|
|
55
|
+
// A malformed escape is still a value; the pattern decides.
|
|
56
|
+
}
|
|
57
|
+
return isClientId(value) ? value : null;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `Set-Cookie` for a client id, `Secure` only when the request came over TLS. */
|
|
63
|
+
export function clientCookieHeader(clientId: string, request: Request): string {
|
|
64
|
+
const attributes = [
|
|
65
|
+
`${CLIENT_COOKIE}=${encodeURIComponent(clientId)}`,
|
|
66
|
+
'Path=/',
|
|
67
|
+
'HttpOnly',
|
|
68
|
+
'SameSite=Lax',
|
|
69
|
+
`Max-Age=${CLIENT_COOKIE_TTL_SECONDS}`,
|
|
70
|
+
];
|
|
71
|
+
if (isSecureRequest(request)) attributes.push('Secure');
|
|
72
|
+
return attributes.join('; ');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The id to use for this request, and the cookie to send back when it is new.
|
|
77
|
+
*
|
|
78
|
+
* `setCookie` is null when the request already carried a valid id, so a normal
|
|
79
|
+
* navigation never rewrites a year-long cookie.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveClientIdentity(request: Request): { clientId: string; setCookie: string | null } {
|
|
82
|
+
const existing = readClientId(request);
|
|
83
|
+
if (existing) return { clientId: existing, setCookie: null };
|
|
84
|
+
const clientId = randomUUID();
|
|
85
|
+
return { clientId, setCookie: clientCookieHeader(clientId, request) };
|
|
86
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The client identity behind "last opened session", and why each rule exists.
|
|
8
|
+
*
|
|
9
|
+
* A cookie is the one channel a WebView already persists per app install, so it
|
|
10
|
+
* carries an opaque id rather than a client-supplied key: a caller that could
|
|
11
|
+
* name its own id could read — or overwrite — another install's pointer. The
|
|
12
|
+
* cases below pin the parse (surrounded by other cookies, malformed escapes),
|
|
13
|
+
* the shape guard, and the one response that mints a new identity.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import {
|
|
18
|
+
CLIENT_COOKIE,
|
|
19
|
+
clientCookieHeader,
|
|
20
|
+
isClientId,
|
|
21
|
+
readClientId,
|
|
22
|
+
resolveClientIdentity,
|
|
23
|
+
} from '@/server/lib/sessions/last-opened-client.server';
|
|
24
|
+
|
|
25
|
+
const ID = '11111111-2222-4333-8444-555555555555';
|
|
26
|
+
|
|
27
|
+
function requestWithCookie(cookie: string, url = 'http://localhost/'): Request {
|
|
28
|
+
return new Request(url, { headers: { cookie } });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('readClientId', () => {
|
|
32
|
+
test('finds the id among the other cookies the page sends', () => {
|
|
33
|
+
const request = requestWithCookie(`omp_session_7801=abc; ${CLIENT_COOKIE}=${ID}; theme=dark`);
|
|
34
|
+
expect(readClientId(request)).toBe(ID);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('no cookie header, or an empty value, is no identity', () => {
|
|
38
|
+
expect(readClientId(new Request('http://localhost/'))).toBeNull();
|
|
39
|
+
expect(readClientId(requestWithCookie(`${CLIENT_COOKIE}=`))).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('a value this server would not mint is refused', () => {
|
|
43
|
+
for (const value of ['short', 'has spaces', 'a'.repeat(65), '../escape']) {
|
|
44
|
+
expect(readClientId(requestWithCookie(`${CLIENT_COOKIE}=${encodeURIComponent(value)}`))).toBeNull();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('a malformed escape still answers a decodable value or null', () => {
|
|
49
|
+
expect(readClientId(requestWithCookie(`${CLIENT_COOKIE}=%E0%A4%A`))).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('isClientId', () => {
|
|
54
|
+
test('accepts the UUID shape it generates and length bounds the rest', () => {
|
|
55
|
+
expect(isClientId(ID)).toBe(true);
|
|
56
|
+
expect(isClientId('a'.repeat(16))).toBe(true);
|
|
57
|
+
expect(isClientId('a'.repeat(15))).toBe(false);
|
|
58
|
+
expect(isClientId('a'.repeat(65))).toBe(false);
|
|
59
|
+
expect(isClientId(undefined)).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('resolveClientIdentity', () => {
|
|
64
|
+
test('an existing id is reused and no cookie is rewritten', () => {
|
|
65
|
+
const identity = resolveClientIdentity(requestWithCookie(`${CLIENT_COOKIE}=${ID}`));
|
|
66
|
+
expect(identity.clientId).toBe(ID);
|
|
67
|
+
expect(identity.setCookie).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('a missing id mints one and returns its cookie', () => {
|
|
71
|
+
const identity = resolveClientIdentity(new Request('http://localhost/'));
|
|
72
|
+
expect(isClientId(identity.clientId)).toBe(true);
|
|
73
|
+
expect(identity.setCookie).toContain(`${CLIENT_COOKIE}=${identity.clientId}`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('clientCookieHeader', () => {
|
|
78
|
+
test('is a long-lived, script-invisible cookie scoped to the whole app', () => {
|
|
79
|
+
const header = clientCookieHeader(ID, new Request('http://localhost/'));
|
|
80
|
+
expect(header).toContain(`${CLIENT_COOKIE}=${ID}`);
|
|
81
|
+
expect(header).toContain('Path=/');
|
|
82
|
+
expect(header).toContain('HttpOnly');
|
|
83
|
+
expect(header).toContain('SameSite=Lax');
|
|
84
|
+
expect(header).toContain('Max-Age=31536000');
|
|
85
|
+
expect(header).not.toContain('Secure');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('Secure rides only on a TLS request', () => {
|
|
89
|
+
expect(clientCookieHeader(ID, new Request('https://localhost/'))).toContain('Secure');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The last-opened record: what a native shell is allowed to restore.
|
|
8
|
+
*
|
|
9
|
+
* Every case is a reason a cold start could land somewhere wrong — a pending
|
|
10
|
+
* placeholder, a path-shaped id, a session the user archived or deleted — and
|
|
11
|
+
* the assertion is always the same pair: the read refuses, AND the stale row is
|
|
12
|
+
* gone, because a record that survives its session makes every later launch pay
|
|
13
|
+
* the same failure again.
|
|
14
|
+
*
|
|
15
|
+
* The first case is the feature's whole reason for a client key: two installs
|
|
16
|
+
* pointing at one console must not share a pointer.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
20
|
+
import { getDb } from '@/server/db.server';
|
|
21
|
+
import type { DbClient } from '@kabmo-labs/kabmo-db/client';
|
|
22
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
23
|
+
import {
|
|
24
|
+
clearLastOpenedSession,
|
|
25
|
+
lastOpenedSession,
|
|
26
|
+
readLastOpenedSessionId,
|
|
27
|
+
recordLastOpenedSession,
|
|
28
|
+
} from '@/server/lib/sessions/last-opened.server';
|
|
29
|
+
|
|
30
|
+
const SESSION_ID = '42';
|
|
31
|
+
const CLIENT = '11111111-2222-4333-8444-555555555555';
|
|
32
|
+
const OTHER_CLIENT = '99999999-8888-4777-8666-555555555555';
|
|
33
|
+
let db: DbClient;
|
|
34
|
+
let priorMock: string | undefined;
|
|
35
|
+
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
priorMock = Bun.env.MOCK;
|
|
38
|
+
Bun.env.MOCK = 'true';
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
await isolateDb();
|
|
43
|
+
db = await getDb();
|
|
44
|
+
// A mock session outside the seeded demo rows, so nothing else can answer
|
|
45
|
+
// for it.
|
|
46
|
+
await db.run("INSERT OR IGNORE INTO workspace_folders (id, name) VALUES (7, 'test')");
|
|
47
|
+
await db.run('INSERT INTO sessions (id, folder_id, title) VALUES (?, 7, ?)', [SESSION_ID, 'Probe']);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(async () => {
|
|
51
|
+
await releaseDb();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterAll(() => {
|
|
55
|
+
if (priorMock === undefined) delete Bun.env.MOCK;
|
|
56
|
+
else Bun.env.MOCK = priorMock;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('lastOpenedSession', () => {
|
|
60
|
+
test('no record yet means no session to restore', async () => {
|
|
61
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a recorded session that still exists is restored', async () => {
|
|
65
|
+
expect(await recordLastOpenedSession(CLIENT, SESSION_ID)).toBe(true);
|
|
66
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBe(SESSION_ID);
|
|
67
|
+
expect(await lastOpenedSession(CLIENT)).toBe(SESSION_ID);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('two clients keep separate pointers at one console', async () => {
|
|
71
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
72
|
+
|
|
73
|
+
// The second install never opened anything, so it restores the landing even
|
|
74
|
+
// though the first install has a record.
|
|
75
|
+
expect(await lastOpenedSession(OTHER_CLIENT)).toBeNull();
|
|
76
|
+
expect(await readLastOpenedSessionId(OTHER_CLIENT)).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('an archived session is refused and its record cleared', async () => {
|
|
80
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
81
|
+
await db.run('INSERT OR IGNORE INTO archived_sessions (session_id) VALUES (?)', [SESSION_ID]);
|
|
82
|
+
|
|
83
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
84
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('a tombstoned session is refused and its record cleared', async () => {
|
|
88
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
89
|
+
await db.run('INSERT OR IGNORE INTO deleted_sessions (session_id) VALUES (?)', [SESSION_ID]);
|
|
90
|
+
|
|
91
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
92
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('an id that no longer exists is refused and its record cleared', async () => {
|
|
96
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
97
|
+
await db.run('DELETE FROM sessions WHERE id = ?', [SESSION_ID]);
|
|
98
|
+
|
|
99
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
100
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('clearing leaves the next launch on the empty workspace', async () => {
|
|
104
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
105
|
+
await clearLastOpenedSession(CLIENT);
|
|
106
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('recordLastOpenedSession', () => {
|
|
111
|
+
test('a pending chat is not a session to reopen', async () => {
|
|
112
|
+
expect(await recordLastOpenedSession(CLIENT, 'new-1761000000000')).toBe(false);
|
|
113
|
+
expect(await recordLastOpenedSession(CLIENT, '__new__01a0ff3d-0000-7000-8000-000000000000')).toBe(false);
|
|
114
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('a value that is not one path segment is refused', async () => {
|
|
118
|
+
for (const id of ['', '.', '..', 'a/b', 'a\\b']) {
|
|
119
|
+
expect(await recordLastOpenedSession(CLIENT, id)).toBe(false);
|
|
120
|
+
}
|
|
121
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('a request with no client id records nothing', async () => {
|
|
125
|
+
expect(await recordLastOpenedSession('', SESSION_ID)).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
});
|