@@ -11,7 +11,7 @@ import {
1111 normalizeInitialApplicationLocation ,
1212 resolveInitialApplicationLocation ,
1313} from "./bootstrap-location.ts" ;
14- import { bootstrapApplication } from "./bootstrap.ts" ;
14+ import { bootstrapApplication , createSkillWorkshopRevisionHandoff } from "./bootstrap.ts" ;
1515import type { ApplicationContext } from "./context.ts" ;
1616import { loadSettings , saveSettings } from "./settings.ts" ;
1717
@@ -28,6 +28,59 @@ function deferred<T>() {
2828 return { promise, resolve } ;
2929}
3030
31+ describe ( "createSkillWorkshopRevisionHandoff" , ( ) => {
32+ it ( "does not consume a handoff through a replacement snapshot with the same client" , ( ) => {
33+ const client = { request : vi . fn ( ) } as unknown as GatewayBrowserClient ;
34+ const owner = {
35+ phase : "connected" ,
36+ client,
37+ hello : null ,
38+ } as ApplicationContext [ "gateway" ] [ "snapshot" ] ;
39+ const replacement = { ...owner } ;
40+ const handoff = {
41+ sessionKey : "agent:main:revision" ,
42+ instructions : "Revise the skill." ,
43+ owner,
44+ proposalId : "proposal-1" ,
45+ proposalAgentId : "main" ,
46+ } ;
47+ const revisions = createSkillWorkshopRevisionHandoff ( ) ;
48+
49+ revisions . prepare ( handoff ) ;
50+
51+ expect ( revisions . consume ( handoff . sessionKey , replacement ) ) . toBeNull ( ) ;
52+ expect ( revisions . consume ( handoff . sessionKey , owner ) ) . toEqual ( handoff ) ;
53+ } ) ;
54+
55+ it ( "clears only the handoff that became stale" , ( ) => {
56+ const owner = {
57+ phase : "connected" ,
58+ client : { request : vi . fn ( ) } as unknown as GatewayBrowserClient ,
59+ hello : null ,
60+ } as ApplicationContext [ "gateway" ] [ "snapshot" ] ;
61+ const stale = {
62+ sessionKey : "agent:main:stale" ,
63+ instructions : "Stale revision." ,
64+ owner,
65+ proposalId : "proposal-stale" ,
66+ proposalAgentId : "main" ,
67+ } ;
68+ const current = {
69+ ...stale ,
70+ sessionKey : "agent:main:current" ,
71+ instructions : "Current revision." ,
72+ proposalId : "proposal-current" ,
73+ } ;
74+ const revisions = createSkillWorkshopRevisionHandoff ( ) ;
75+
76+ revisions . prepare ( stale ) ;
77+ revisions . prepare ( current ) ;
78+ revisions . clear ( stale ) ;
79+
80+ expect ( revisions . consume ( current . sessionKey , owner ) ) . toEqual ( current ) ;
81+ } ) ;
82+ } ) ;
83+
3184describe ( "normalizeInitialApplicationLocation" , ( ) => {
3285 it ( "routes an opaque persisted key without aborting bootstrap" , ( ) => {
3386 expect (
0 commit comments