@@ -5,6 +5,34 @@ import * as NodeFS from "node:fs";
55import * as NodeOS from "node:os" ;
66import * as NodePath from "node:path" ;
77
8+ const runDevSeed = ( input : {
9+ readonly root : string ;
10+ readonly targetBaseDir : string ;
11+ readonly t3Home : string ;
12+ } ) =>
13+ NodeChildProcess . spawnSync (
14+ process . execPath ,
15+ [
16+ NodePath . join ( import . meta. dirname , "dev-seed.ts" ) ,
17+ "--from" ,
18+ NodePath . join ( input . root , "source" ) ,
19+ "--to" ,
20+ input . targetBaseDir ,
21+ ] ,
22+ {
23+ encoding : "utf8" ,
24+ env : { ...process . env , NO_COLOR : "1" , T3CODE_HOME : input . t3Home } ,
25+ } ,
26+ ) ;
27+
28+ const assertSharedHomeRefusal = ( result : ReturnType < typeof runDevSeed > ) => {
29+ assert . notEqual ( result . status , 0 ) ;
30+ assert . include (
31+ `${ result . stdout } ${ result . stderr } ` ,
32+ "that database lives in the shared T3 Code home" ,
33+ ) ;
34+ } ;
35+
836it ( "refuses to seed a target inside T3CODE_HOME through a symlink" , ( ) => {
937 const root = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-dev-seed-cli-" ) ) ;
1038 try {
@@ -16,26 +44,9 @@ it("refuses to seed a target inside T3CODE_HOME through a symlink", () => {
1644 NodeFS . writeFileSync ( NodePath . join ( sharedStateDir , "state.sqlite" ) , "must stay untouched" ) ;
1745 NodeFS . symlinkSync ( sharedStateDir , NodePath . join ( targetBaseDir , "userdata" ) , "dir" ) ;
1846
19- const result = NodeChildProcess . spawnSync (
20- process . execPath ,
21- [
22- NodePath . join ( import . meta. dirname , "dev-seed.ts" ) ,
23- "--from" ,
24- NodePath . join ( root , "source" ) ,
25- "--to" ,
26- targetBaseDir ,
27- ] ,
28- {
29- encoding : "utf8" ,
30- env : { ...process . env , NO_COLOR : "1" , T3CODE_HOME : sharedHome } ,
31- } ,
32- ) ;
47+ const result = runDevSeed ( { root, targetBaseDir, t3Home : sharedHome } ) ;
3348
34- assert . notEqual ( result . status , 0 ) ;
35- assert . include (
36- `${ result . stdout } ${ result . stderr } ` ,
37- "that database lives in the shared T3 Code home" ,
38- ) ;
49+ assertSharedHomeRefusal ( result ) ;
3950 assert . equal (
4051 NodeFS . readFileSync ( NodePath . join ( sharedStateDir , "state.sqlite" ) , "utf8" ) ,
4152 "must stay untouched" ,
@@ -44,3 +55,25 @@ it("refuses to seed a target inside T3CODE_HOME through a symlink", () => {
4455 NodeFS . rmSync ( root , { recursive : true , force : true } ) ;
4556 }
4657} ) ;
58+
59+ it ( "refuses targets when T3CODE_HOME resolves to the filesystem root" , ( ) => {
60+ const root = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-dev-seed-root-cli-" ) ) ;
61+ try {
62+ const sharedHome = NodePath . join ( root , "shared" ) ;
63+ const targetBaseDir = NodePath . join ( root , "target" ) ;
64+ const targetStateDir = NodePath . join ( targetBaseDir , "userdata" ) ;
65+ NodeFS . symlinkSync ( NodePath . parse ( root ) . root , sharedHome , "dir" ) ;
66+ NodeFS . mkdirSync ( targetStateDir , { recursive : true } ) ;
67+ NodeFS . writeFileSync ( NodePath . join ( targetStateDir , "state.sqlite" ) , "must stay untouched" ) ;
68+
69+ const result = runDevSeed ( { root, targetBaseDir, t3Home : sharedHome } ) ;
70+
71+ assertSharedHomeRefusal ( result ) ;
72+ assert . equal (
73+ NodeFS . readFileSync ( NodePath . join ( targetStateDir , "state.sqlite" ) , "utf8" ) ,
74+ "must stay untouched" ,
75+ ) ;
76+ } finally {
77+ NodeFS . rmSync ( root , { recursive : true , force : true } ) ;
78+ }
79+ } ) ;
0 commit comments