@kabmo-labs/kabmo 0.53.1 → 0.54.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 +529 -518
- package/dist/client/static/js/{Body-3v975hq3.js → Body-x5grdps8.js} +1 -1
- package/dist/client/static/js/{CsvGrid-8xcj58sw.js → CsvGrid-248v9yzf.js} +1 -1
- package/dist/client/static/js/{DocxView-fwmfpsg7.js → DocxView-5we92k2h.js} +1 -1
- package/dist/client/static/js/{DrawioView-gdtqj2vv.js → DrawioView-c6xmw4qq.js} +1 -1
- package/dist/client/static/js/{HtmlPreview-g4bp5mgq.js → HtmlPreview-r3qxgqg6.js} +1 -1
- package/dist/client/static/js/{ImageView-5e3vdyc9.js → ImageView-cr4fea18.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-ssxr6q2d.js → LayoutWrapper-j12z0djx.js} +2 -2
- package/dist/client/static/js/MergeDiffView-y0we0194.js +1 -0
- package/dist/client/static/js/{Modal-px8tcv9m.js → Modal-cqceypcn.js} +11 -11
- package/dist/client/static/js/{PdfView-92rx0s88.js → PdfView-xdgn31cm.js} +1 -1
- package/dist/client/static/js/{SessionsView-s3d9nceb.js → SessionsView-ms6z44e2.js} +1 -1
- package/dist/client/static/js/{SheetView-yeg7gtf9.js → SheetView-peqm9vft.js} +1 -1
- package/dist/client/static/js/{SvgPreview-6evr72fg.js → SvgPreview-rdf4wbzr.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-a6n0cab2.js → abnfDiagram-O67JEVCF-48z2x5vg.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-z9k17qfg.js → architectureDiagram-NJMV4G6O-n1pr5s6j.js} +1 -1
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-63d683v3.js → blockDiagram-BEXU5L5S-p19shaft.js} +1 -1
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-5bk6kv13.js → c4Diagram-YGBWAQC7-qcd46ts2.js} +1 -1
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-s6rmr6vt.js → classDiagram-v2-NBCMYWYE-scyhe133.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-wd5v7q2m.js → cose-bilkent-JH36ORCC-srnnj3f7.js} +1 -1
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-j71tvbhy.js → cynefinDiagram-VND7K2PF-1zfrnyay.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-q6x3d9xb.js → dagre-6A5THRUB-hepk25pz.js} +1 -1
- package/dist/client/static/js/{diagram-22UHCM2B-g6e427jm.js → diagram-22UHCM2B-wy2y0323.js} +1 -1
- package/dist/client/static/js/{diagram-3UASUU5V-rg3nty46.js → diagram-3UASUU5V-j904f93p.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-m82xv6ka.js → diagram-ATOU4E4O-2mmxccm2.js} +2 -2
- package/dist/client/static/js/{diagram-CDSNMT55-q3aa8sv0.js → diagram-CDSNMT55-cfhk73ty.js} +3 -3
- package/dist/client/static/js/{diagram-MLGK6HIB-nkyd150x.js → diagram-MLGK6HIB-ryf8j6hf.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-1gchkss2.js → diagram-MPIPVDR6-8k5e36sd.js} +2 -2
- package/dist/client/static/js/{dockerfile-f51g7549.js → dockerfile-1e7deann.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-4dsm3p06.js → ebnfDiagram-ZINNZB2B-5kkbbbhv.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-d8wtwxae.js → elk-276RUBZZ-jqc4mzvc.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-bq865cmc.js → erDiagram-OPXOYQCR-kx15t6f0.js} +1 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-dpjz82p8.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-ndnqbbzn.js → ganttDiagram-FUAMR5RP-3hv8pej4.js} +1 -1
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-d9y6fnz0.js → gitGraphDiagram-X574FWY7-a4mq8vwz.js} +2 -2
- package/dist/client/static/js/{index-z0vvdpkv.js → index-01rdknec.js} +1 -1
- package/dist/client/static/js/{index-0ccj7j87.js → index-0j5ng1qc.js} +1 -1
- package/dist/client/static/js/{index-gm9cqsqg.js → index-0z7kerp1.js} +1 -1
- package/dist/client/static/js/{index-f7sssx5h.js → index-1ye834yz.js} +1 -1
- package/dist/client/static/js/{index-h9p3748x.js → index-317v49ey.js} +2 -2
- package/dist/client/static/js/{index-046kc8ft.js → index-3kenmzbe.js} +1 -1
- package/dist/client/static/js/{index-k8ks184k.js → index-40fdtqvw.js} +1 -1
- package/dist/client/static/js/{index-8k568z0z.js → index-40ydm28n.js} +1 -1
- package/dist/client/static/js/{index-0fpc1h6v.js → index-51wzt3ma.js} +1 -1
- package/dist/client/static/js/{index-7jr49rd4.js → index-8hnem33f.js} +1 -1
- package/dist/client/static/js/{index-6pxh5p8g.js → index-937bn0d2.js} +1 -1
- package/dist/client/static/js/{index-049xtm14.js → index-9cr6p86f.js} +1 -1
- package/dist/client/static/js/{index-7fkdwm69.js → index-9gddw5qy.js} +1 -1
- package/dist/client/static/js/{index-v8fztm3w.js → index-bf54x0w8.js} +1 -1
- package/dist/client/static/js/{index-4pwk5cjy.js → index-br27jz2t.js} +1 -1
- package/dist/client/static/js/{index-w39c85k3.js → index-demg0p74.js} +1 -1
- package/dist/client/static/js/{index-pd4s49n5.js → index-e2y4hkps.js} +1 -1
- package/dist/client/static/js/{index-gr5wd7hv.js → index-eb43hnd3.js} +1 -1
- package/dist/client/static/js/{index-hav1hhbr.js → index-exyg9sna.js} +1 -1
- package/dist/client/static/js/{index-25g1ydkd.js → index-fanhvjk8.js} +1 -1
- package/dist/client/static/js/{index-xf662xsf.js → index-g3x4w48f.js} +1 -1
- package/dist/client/static/js/{index-8w69r0c4.js → index-jvn2xfpt.js} +135 -135
- package/dist/client/static/js/{index-mttf7ej7.js → index-k4kwrze2.js} +1 -1
- package/dist/client/static/js/{index-rc8f8gjk.js → index-kevqayd9.js} +1 -1
- package/dist/client/static/js/{index-mnadx740.js → index-kvker1ps.js} +1 -1
- package/dist/client/static/js/{index-vjk01ja9.js → index-kz5d00m5.js} +1 -1
- package/dist/client/static/js/{index-bcns8arc.js → index-m85c740p.js} +1 -1
- package/dist/client/static/js/{index-53hrj27y.js → index-n3cts2j1.js} +1 -1
- package/dist/client/static/js/{index-hn0brpdf.js → index-n4pm0hrh.js} +4 -4
- package/dist/client/static/js/{index-9eddntv4.js → index-n5194pe6.js} +11 -11
- package/dist/client/static/js/{index-6775m1pa.js → index-p8bta9ae.js} +1 -1
- package/dist/client/static/js/{index-stfccv2r.js → index-pszsxhjr.js} +1 -1
- package/dist/client/static/js/{index-79qddnbx.js → index-rtfw07hy.js} +1 -1
- package/dist/client/static/js/{index-xakrt0sx.js → index-v90zd3sq.js} +1 -1
- package/dist/client/static/js/{index-g46qcgp8.js → index-vxe4e903.js} +1 -1
- package/dist/client/static/js/{index-pnjnvdvb.js → index-w4dep7k6.js} +1 -1
- package/dist/client/static/js/{index-2jtkrmry.js → index-x5c5yxhj.js} +1 -1
- package/dist/client/static/js/{index-5g21qv2b.js → index-xhcbaaga.js} +2 -2
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-t52bsrem.js → infoDiagram-VRGFBTTK-wtnqb06v.js} +1 -1
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-vysv38pr.js → ishikawaDiagram-OU5B5YK6-eta0jnvr.js} +1 -1
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-7222yn0y.js → journeyDiagram-ZHPQQLJL-4e572kkp.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-9cg88rcn.js → kanban-definition-PNTS6WVX-yrtnn4zy.js} +1 -1
- package/dist/client/static/js/{mermaid.core-3qc3zvgb.js → mermaid.core-195b0fb6.js} +3 -3
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-hdbsk349.js → mindmap-definition-NLK3R4M7-pphjnkvt.js} +1 -1
- package/dist/client/static/js/one-dark-pro-asy2qj2p.js +1 -0
- package/dist/client/static/js/one-light-fya1pbbx.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-jtqqcrhq.js → pegDiagram-GJSIUBJH-kgffb9p3.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-2c82jghr.js → pieDiagram-5QR66LMP-efech3mm.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-vp2hw2a8.js → quadrantDiagram-O4NWA36T-khf9cv3t.js} +1 -1
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-4168nq4f.js → railroadDiagram-XR7U4H2S-ye68kdx2.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-gwqcyxag.js → requirementDiagram-PLB6GJNP-3s4smnme.js} +1 -1
- package/dist/client/static/js/{rust-6m8myprw.js → rust-tdrnaxp3.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-y5fakn56.js → sankeyDiagram-IPEJSGJF-9pqd25mc.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-z140kern.js → sequenceDiagram-PO4LG4MO-rka8ct43.js} +1 -1
- package/dist/client/static/js/{sizeCapture-INFHLROL-gfez373x.js → sizeCapture-INFHLROL-g5wkzry8.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-1d6h03nr.js → stateDiagram-v2-GCMORJYK-gy1zab2j.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-75wg3n6d.js → swimlanes-2SLR337P-kr35nmd2.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-18fj17m7.js → swimlanesDiagram-TC7HE7FX-qnhxxmjr.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-q750z70f.js → timeline-definition-EJHVYXUP-sg151mkc.js} +1 -1
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-9q7tg456.js → usecaseDiagram-POWQR4AR-f91g61p3.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-010nw1kd.js → vennDiagram-UO4OBE2U-zbhr4eqf.js} +2 -2
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-7n33n10f.js → wardleyDiagram-VNRHLVJA-6302414n.js} +2 -2
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-7q0n5vvd.js → xychartDiagram-PMCCYNJV-0a47th65.js} +2 -2
- package/package.json +2 -2
- package/src/client/App.tsx +4 -0
- package/src/client/bootstrap.d.ts +11 -0
- package/src/client/components/workspace/git-panel/index.test.ts +56 -7
- package/src/client/components/workspace/git-panel/index.tsx +9 -4
- package/src/client/components/workspace/repo-picker/index.test.tsx +29 -2
- package/src/client/data/settings/omp-schema.json +11 -1
- 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/hooks/workspace/commit-box.ts +6 -1
- 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/fs/fs-write-git.test.ts +17 -0
- package/src/server/lib/fs/git-repos.ts +32 -11
- 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/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/omp/config/schema-releases.test.ts +15 -0
- package/dist/client/static/js/MergeDiffView-6t5t6exc.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-z01c78q6.js +0 -1
- package/dist/client/static/js/one-dark-pro-3570ra7e.js +0 -1
- package/dist/client/static/js/one-light-3v5yk200.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
|
+
}
|
|
@@ -153,7 +153,12 @@ export function useCommitBox({ rootPath, repo, execute }: UseCommitBoxOptions):
|
|
|
153
153
|
|
|
154
154
|
const params = new URLSearchParams({ headMessage: '1' });
|
|
155
155
|
if (rootPath) params.set('root', rootPath);
|
|
156
|
-
|
|
156
|
+
// ALWAYS send the repo, including `'.'`. The route's implicit-repo
|
|
157
|
+
// fallback (`repos.includes('.') ? '.' : repos[0]`) exists for a request
|
|
158
|
+
// that names none, so omitting the root pick made amend read the FIRST
|
|
159
|
+
// nested repo's HEAD message while the panel was on the workspace root —
|
|
160
|
+
// a different repository's commit seeded into the draft.
|
|
161
|
+
if (repo) params.set('repo', repo);
|
|
157
162
|
|
|
158
163
|
let cancelled = false;
|
|
159
164
|
void fetch(`/api/fs/git?${params.toString()}`)
|
|
@@ -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
|
|
@@ -280,4 +280,21 @@ describe('git-repos discovery', () => {
|
|
|
280
280
|
rescanRepos(root);
|
|
281
281
|
expect((await settled(root)).repos).toContain('two');
|
|
282
282
|
});
|
|
283
|
+
|
|
284
|
+
test('a rescan keeps the previous list while its walk runs', async () => {
|
|
285
|
+
// The topic answers whatever `discoveredRepos` holds, and every picker on
|
|
286
|
+
// the root renders it. Blanking the cache to `['.']` for the length of the
|
|
287
|
+
// walk made a refresh drop every nested row — including the selected one,
|
|
288
|
+
// whose absence made the picker name the workspace ROOT instead.
|
|
289
|
+
const root = tempDir('repos');
|
|
290
|
+
gitInit(join(root, 'one'));
|
|
291
|
+
startRepoScan(root);
|
|
292
|
+
const first = await settled(root);
|
|
293
|
+
|
|
294
|
+
rescanRepos(root);
|
|
295
|
+
expect(discoveredRepos(root)).toEqual({ repos: first.repos, pending: true });
|
|
296
|
+
|
|
297
|
+
const second = await settled(root);
|
|
298
|
+
expect(second.repos).toContain('one');
|
|
299
|
+
});
|
|
283
300
|
});
|
|
@@ -86,32 +86,53 @@ interface RepoDiscovery {
|
|
|
86
86
|
|
|
87
87
|
const repoDiscovery = new Map<string, RepoDiscovery>();
|
|
88
88
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Begin a background walk for `rootDir`, seeded with the list the client should
|
|
91
|
+
* see while it runs.
|
|
92
|
+
*
|
|
93
|
+
* The seed is why this is not inlined into `startRepoScan`: a FORCED rescan
|
|
94
|
+
* answers with the previous list, so the picker keeps the rows (and the pick's
|
|
95
|
+
* own row) instead of collapsing to the bare root for the length of the walk.
|
|
96
|
+
*/
|
|
97
|
+
function beginScan(rootDir: string, seed: string[]): void {
|
|
98
|
+
const d: RepoDiscovery = { repos: seed, done: false };
|
|
93
99
|
repoDiscovery.set(rootDir, d);
|
|
94
100
|
void getRepos(rootDir)
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
// A newer scan may have replaced this entry (two rescans in flight, or a
|
|
102
|
+
// walk that outlived a rescan): only the CURRENT walk owns the cache.
|
|
103
|
+
.then(repos => { if (repoDiscovery.get(rootDir) === d) { d.repos = repos; d.done = true; } })
|
|
104
|
+
.catch(() => { if (repoDiscovery.get(rootDir) === d) { d.repos = ['.']; d.done = true; } })
|
|
97
105
|
// The walk is STARTED by a read, so this completion is the only moment the
|
|
98
106
|
// list becomes final — the `repos:` topic is re-snapshotted from it, and a
|
|
99
107
|
// client watching the root never has to poll for the answer.
|
|
100
|
-
.finally(() =>
|
|
108
|
+
.finally(() => {
|
|
109
|
+
if (repoDiscovery.get(rootDir) === d) emitRealtimeSignal('repos-scanned', undefined, rootDir);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Begin the background walk for `rootDir`; a no-op once one has started. */
|
|
114
|
+
export function startRepoScan(rootDir: string): void {
|
|
115
|
+
if (repoDiscovery.has(rootDir)) return;
|
|
116
|
+
beginScan(rootDir, ['.']);
|
|
101
117
|
}
|
|
102
118
|
|
|
103
119
|
/**
|
|
104
|
-
*
|
|
120
|
+
* Start a fresh walk for `rootDir`, ignoring the cached result. Used by the
|
|
105
121
|
* repo-switcher's refresh button, which must not serve the previous answer.
|
|
122
|
+
*
|
|
123
|
+
* The PREVIOUS list is published while the new walk runs: the topic would
|
|
124
|
+
* otherwise report `['.']` as if discovery had found one repository, and every
|
|
125
|
+
* picker on the root dropped its nested rows — including the selected one —
|
|
126
|
+
* until the walk finished.
|
|
106
127
|
*/
|
|
107
128
|
export function rescanRepos(rootDir: string): void {
|
|
108
|
-
repoDiscovery.
|
|
109
|
-
|
|
129
|
+
const previous = repoDiscovery.get(rootDir)?.repos ?? ['.'];
|
|
130
|
+
beginScan(rootDir, previous);
|
|
110
131
|
}
|
|
111
132
|
|
|
112
133
|
/** The discovered repos for `rootDir`, and whether the walk is still running. */
|
|
113
134
|
export function discoveredRepos(rootDir: string): { repos: string[]; pending: boolean } {
|
|
114
135
|
const d = repoDiscovery.get(rootDir);
|
|
115
136
|
if (!d) return { repos: ['.'], pending: false };
|
|
116
|
-
return { repos: d.
|
|
137
|
+
return { repos: d.repos, pending: !d.done };
|
|
117
138
|
}
|
|
@@ -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
|
+
});
|