@@ -32,65 +32,73 @@ import { Server } from "../../src/server/server"
3232import { WORKSPACE_PILOT_OFF_MESSAGE } from "../../src/cli/cmd/workspace-pilot"
3333
3434const SNAP = path . join ( ".altimate-code" , "skill" , "_workspace" )
35+ // Native absolute paths, so the expectations hold on Windows (drive-qualified, `\\`) as on POSIX.
36+ const ROOT = path . parse ( process . cwd ( ) ) . root
37+ const abs = ( ...parts : string [ ] ) => path . join ( ROOT , ...parts )
38+ const P = abs ( "p" )
3539
3640describe ( "v0.12.4 adversarial: snapshot attribution by path segments" , ( ) => {
3741 test ( "a traversal out of the snapshot is not attributed to it" , ( ) => {
38- // Resolves to /p/.altimate-code/evil — no `_workspace` segment survives.
39- expect ( snapshotProjectOf ( `/p/ ${ SNAP } /../../ evil/ SKILL.md` ) ) . toBeNull ( )
42+ // Resolves to <root> /p/.altimate-code/evil — no `_workspace` segment survives.
43+ expect ( snapshotProjectOf ( `${ P } ${ path . sep } ${ SNAP } ${ path . sep } .. ${ path . sep } .. ${ path . sep } evil${ path . sep } SKILL.md` ) ) . toBeNull ( )
4044 } )
4145
4246 test ( "a traversal INTO the snapshot is attributed after resolution" , ( ) => {
43- expect ( snapshotProjectOf ( `/p/x/../ ${ SNAP } /a/ SKILL.md` ) ) . toBe ( "/p" )
47+ expect ( snapshotProjectOf ( `${ P } ${ path . sep } x ${ path . sep } .. ${ path . sep } ${ SNAP } ${ path . sep } a ${ path . sep } SKILL.md` ) ) . toBe ( P )
4448 } )
4549
4650 test ( "lookalike segments are not a snapshot" , ( ) => {
47- expect ( snapshotProjectOf ( "/p/ .altimate-code/ skill/ _workspace2/a/ SKILL.md") ) . toBeNull ( )
48- expect ( snapshotProjectOf ( "/p/ .altimate-code-x/ skill/ _workspace/a/ SKILL.md") ) . toBeNull ( )
49- expect ( snapshotProjectOf ( "/p/ .altimate-code/ skills/ _workspace/a/ SKILL.md") ) . toBeNull ( )
50- expect ( snapshotProjectOf ( "/p/ _workspace/ skill/ .altimate-code/a/ SKILL.md") ) . toBeNull ( )
51+ expect ( snapshotProjectOf ( abs ( "p" , " .altimate-code" , " skill" , " _workspace2" , "a" , " SKILL.md") ) ) . toBeNull ( )
52+ expect ( snapshotProjectOf ( abs ( "p" , " .altimate-code-x" , " skill" , " _workspace" , "a" , " SKILL.md") ) ) . toBeNull ( )
53+ expect ( snapshotProjectOf ( abs ( "p" , " .altimate-code" , " skills" , " _workspace" , "a" , " SKILL.md") ) ) . toBeNull ( )
54+ expect ( snapshotProjectOf ( abs ( "p" , " _workspace" , " skill" , " .altimate-code" , "a" , " SKILL.md") ) ) . toBeNull ( )
5155 } )
5256
53- test ( "a project opened at the filesystem root is `/`, not 'no project'" , ( ) => {
54- expect ( snapshotProjectOf ( `/${ SNAP } /a/SKILL.md` ) ) . toBe ( "/" )
57+ test ( "a project opened at the filesystem root is the root, not 'no project'" , ( ) => {
58+ const result = snapshotProjectOf ( abs ( SNAP , "a" , "SKILL.md" ) )
59+ expect ( result ) . not . toBeNull ( )
60+ expect ( path . resolve ( result ! ) ) . toBe ( path . resolve ( ROOT ) )
5561 } )
5662
5763 test ( "nested snapshots attribute to the outermost project" , ( ) => {
58- expect ( snapshotProjectOf ( `/p/ ${ SNAP } /q/ ${ SNAP } /a/ SKILL.md` ) ) . toBe ( "/p" )
64+ expect ( snapshotProjectOf ( abs ( "p" , SNAP , "q" , SNAP , "a" , " SKILL.md" ) ) ) . toBe ( P )
5965 } )
6066
6167 test ( "isWithin refuses a prefix sibling and a parent" , ( ) => {
62- expect ( isWithin ( "/proj ", "/proj2/ SKILL.md" ) ) . toBe ( false )
63- expect ( isWithin ( "/proj" , "/" ) ) . toBe ( false )
64- expect ( isWithin ( "/proj" , "/proj" ) ) . toBe ( true )
65- expect ( isWithin ( "/proj" , "/proj/a/../b" ) ) . toBe ( true )
66- expect ( isWithin ( "/proj" , "/proj/../proj2" ) ) . toBe ( false )
68+ expect ( isWithin ( P , abs ( "p2 ", "SKILL.md" ) ) ) . toBe ( false )
69+ expect ( isWithin ( P , ROOT ) ) . toBe ( false )
70+ expect ( isWithin ( P , P ) ) . toBe ( true )
71+ expect ( isWithin ( P , ` ${ P } ${ path . sep } a ${ path . sep } .. ${ path . sep } b` ) ) . toBe ( true )
72+ expect ( isWithin ( P , ` ${ P } ${ path . sep } .. ${ path . sep } p2` ) ) . toBe ( false )
6773 } )
6874} )
6975
7076describe ( "v0.12.4 adversarial: snapshotCopyYields type confusion" , ( ) => {
71- const match = `/proj/${ SNAP } /pub-1/SKILL.md`
77+ const PROJ = abs ( "proj" )
78+ const match = abs ( "proj" , SNAP , "pub-1" , "SKILL.md" )
79+ const own = abs ( "proj" , ".claude" , "skills" , "x" , "SKILL.md" )
7280
7381 test ( "non-string or relative existing locations never make the workspace copy yield" , ( ) => {
7482 for ( const existing of [ undefined , null , 0 , 1 , { } , [ ] , true , "builtin:x" , "<built-in>" , "relative/SKILL.md" , "" ] ) {
75- expect ( snapshotCopyYields ( match , existing as unknown , "/proj" ) ) . toBe ( false )
83+ expect ( snapshotCopyYields ( match , existing as unknown , PROJ ) ) . toBe ( false )
7684 }
7785 } )
7886
7987 test ( "no project root means no protection" , ( ) => {
80- expect ( snapshotCopyYields ( match , "/proj/.claude/skills/x/SKILL.md" , undefined ) ) . toBe ( false )
81- expect ( snapshotCopyYields ( match , "/proj/.claude/skills/x/SKILL.md" , "" ) ) . toBe ( false )
88+ expect ( snapshotCopyYields ( match , own , undefined ) ) . toBe ( false )
89+ expect ( snapshotCopyYields ( match , own , "" ) ) . toBe ( false )
8290 } )
8391
8492 test ( "only a project skill inside the root wins over the workspace copy" , ( ) => {
85- expect ( snapshotCopyYields ( match , "/proj/.claude/skills/x/SKILL.md" , "/proj" ) ) . toBe ( true )
86- expect ( snapshotCopyYields ( match , "/ proj2/ .claude/ skills/x/ SKILL.md", "/proj" ) ) . toBe ( false )
87- expect ( snapshotCopyYields ( match , "/ home/me/ .claude/ skills/x/ SKILL.md", "/proj" ) ) . toBe ( false )
93+ expect ( snapshotCopyYields ( match , own , PROJ ) ) . toBe ( true )
94+ expect ( snapshotCopyYields ( match , abs ( " proj2" , " .claude" , " skills" , "x" , " SKILL.md") , PROJ ) ) . toBe ( false )
95+ expect ( snapshotCopyYields ( match , abs ( " home" , "me" , " .claude" , " skills" , "x" , " SKILL.md") , PROJ ) ) . toBe ( false )
8896 // Another snapshot entry is not the user's own skill.
89- expect ( snapshotCopyYields ( match , `/ proj/ ${ SNAP } / pub-2/ SKILL.md` , "/proj" ) ) . toBe ( false )
97+ expect ( snapshotCopyYields ( match , abs ( " proj" , SNAP , " pub-2" , " SKILL.md" ) , PROJ ) ) . toBe ( false )
9098 } )
9199
92100 test ( "a non-snapshot match never yields, whatever it collides with" , ( ) => {
93- expect ( snapshotCopyYields ( "/ proj/ .claude/ skills/y/SKILL.md ", "/proj/.claude/skills/x/ SKILL.md" , "/proj" ) ) . toBe ( false )
101+ expect ( snapshotCopyYields ( abs ( " proj" , " .claude" , " skills" , "y ", "SKILL.md" ) , own , PROJ ) ) . toBe ( false )
94102 } )
95103} )
96104
@@ -228,9 +236,9 @@ describe("v0.12.4 adversarial: workspace route gate", () => {
228236 } )
229237
230238 test ( "an origin on an unsecured server is refused; a native client is not" , ( ) => {
231- expect ( Server . workspaceRouteRefusal ( "http://127.0.0.1:4096" , "127.0.0.1:4096" , undefined ) ?. status ) . toBe ( 403 )
239+ // "" rather than undefined: undefined selects the default, the environment's server password.
232240 expect ( Server . workspaceRouteRefusal ( "http://127.0.0.1:4096" , "127.0.0.1:4096" , "" ) ?. status ) . toBe ( 403 )
233- expect ( Server . workspaceRouteRefusal ( undefined , "127.0.0.1:4096" , undefined ) ) . toBeUndefined ( )
241+ expect ( Server . workspaceRouteRefusal ( undefined , "127.0.0.1:4096" , "" ) ) . toBeUndefined ( )
234242 } )
235243
236244 test ( "with a password, malformed and lookalike origins are refused" , ( ) => {
0 commit comments