@@ -78,19 +78,22 @@ describe("registerAdrListCommand", () => {
7878
7979describe ( "adr list action handler" , ( ) => {
8080 let tempDir : string ;
81+ let adrsDir : string ;
8182 let originalCwd : string ;
8283 let logSpy : ReturnType < typeof spyOn > ;
8384 let exitSpy : ReturnType < typeof spyOn > ;
8485
8586 beforeEach ( ( ) => {
8687 tempDir = mkdtempSync ( join ( tmpdir ( ) , "archgate-list-test-" ) ) ;
88+ adrsDir = join ( tempDir , ".archgate" , "adrs" ) ;
8789 originalCwd = process . cwd ( ) ;
8890 // Prevent findProjectRoot() from walking above the temp dir
8991 Bun . env . ARCHGATE_PROJECT_CEILING = tempDir ;
9092 logSpy = spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
9193 exitSpy = spyOn ( process , "exit" ) . mockImplementation ( ( ) => {
9294 throw new Error ( "process.exit" ) ;
9395 } ) ;
96+ process . chdir ( tempDir ) ;
9497 } ) ;
9598
9699 afterEach ( ( ) => {
@@ -107,141 +110,128 @@ describe("adr list action handler", () => {
107110 return parent ;
108111 }
109112
110- test ( "lists ADRs from .archgate/adrs/ directory in table format" , async ( ) => {
111- const adrsDir = join ( tempDir , ".archgate" , "adrs" ) ;
112- mkdirSync ( adrsDir , { recursive : true } ) ;
113- writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
114- writeFileSync (
115- join ( adrsDir , "GEN-001-use-conventional-commits.md" ) ,
116- ADR_CONTENT_2
117- ) ;
118-
119- process . chdir ( tempDir ) ;
120- const parent = makeProgram ( ) ;
121- await parent . parseAsync ( [ "node" , "adr" , "list" ] ) ;
122-
123- const allOutput = logSpy . mock . calls
124- . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
125- . join ( "\n" ) ;
126- expect ( allOutput ) . toContain ( "ARCH-001" ) ;
127- expect ( allOutput ) . toContain ( "GEN-001" ) ;
128- } ) ;
129-
130- test ( "outputs JSON when --json flag is passed" , async ( ) => {
131- const adrsDir = join ( tempDir , ".archgate" , "adrs" ) ;
132- mkdirSync ( adrsDir , { recursive : true } ) ;
133- writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
134-
135- process . chdir ( tempDir ) ;
136- const parent = makeProgram ( ) ;
137- await parent . parseAsync ( [ "node" , "adr" , "list" , "--json" ] ) ;
138-
139- const allOutput = logSpy . mock . calls
140- . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
141- . join ( "\n" ) ;
142- const parsed = JSON . parse ( allOutput ) ;
143- expect ( Array . isArray ( parsed ) ) . toBe ( true ) ;
144- expect ( parsed [ 0 ] . id ) . toBe ( "ARCH-001" ) ;
145- expect ( parsed [ 0 ] . domain ) . toBe ( "architecture" ) ;
146- } ) ;
113+ describe ( "with .archgate/adrs scaffolded" , ( ) => {
114+ beforeEach ( ( ) => {
115+ mkdirSync ( adrsDir , { recursive : true } ) ;
116+ } ) ;
147117
148- test ( "JSON output carries identity fields only, omitting files globs" , async ( ) => {
149- const adrsDir = join ( tempDir , ".archgate" , "adrs" ) ;
150- mkdirSync ( adrsDir , { recursive : true } ) ;
151- writeFileSync (
152- join ( adrsDir , "BE-001-api-response-envelope.md" ) ,
153- ADR_CONTENT_WITH_FILES
154- ) ;
118+ test ( "lists ADRs from .archgate/adrs/ directory in table format" , async ( ) => {
119+ writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
120+ writeFileSync (
121+ join ( adrsDir , "GEN-001-use-conventional-commits.md" ) ,
122+ ADR_CONTENT_2
123+ ) ;
124+
125+ const parent = makeProgram ( ) ;
126+ await parent . parseAsync ( [ "node" , "adr" , "list" ] ) ;
127+
128+ const allOutput = logSpy . mock . calls
129+ . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
130+ . join ( "\n" ) ;
131+ expect ( allOutput ) . toContain ( "ARCH-001" ) ;
132+ expect ( allOutput ) . toContain ( "GEN-001" ) ;
133+ } ) ;
155134
156- process . chdir ( tempDir ) ;
157- const parent = makeProgram ( ) ;
158- await parent . parseAsync ( [ "node" , "adr" , "list" , "--json" ] ) ;
159-
160- const allOutput = logSpy . mock . calls
161- . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
162- . join ( "\n" ) ;
163- const parsed = JSON . parse ( allOutput ) ;
164-
165- // `files`/`respectGitignore` stay out of the listing so large ADR sets
166- // remain small enough for agents to read inline — `adr show` has the rest.
167- expect ( Object . keys ( parsed [ 0 ] ) . toSorted ( ) ) . toEqual ( [
168- "domain" ,
169- "id" ,
170- "rules" ,
171- "title" ,
172- ] ) ;
173- expect ( allOutput ) . not . toContain ( "src/api/**" ) ;
174- } ) ;
135+ test ( "outputs JSON when --json flag is passed" , async ( ) => {
136+ writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
175137
176- test ( "filters by domain with --domain flag" , async ( ) => {
177- const adrsDir = join ( tempDir , ".archgate" , "adrs" ) ;
178- mkdirSync ( adrsDir , { recursive : true } ) ;
179- writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
180- writeFileSync (
181- join ( adrsDir , "GEN-001-use-conventional-commits.md" ) ,
182- ADR_CONTENT_2
183- ) ;
138+ const parent = makeProgram ( ) ;
139+ await parent . parseAsync ( [ "node" , "adr" , "list" , "--json" ] ) ;
184140
185- process . chdir ( tempDir ) ;
186- const parent = makeProgram ( ) ;
187- await parent . parseAsync ( [
188- "node" ,
189- "adr" ,
190- "list" ,
191- "--domain" ,
192- "architecture" ,
193- ] ) ;
194-
195- const allOutput = logSpy . mock . calls
196- . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
197- . join ( "\n" ) ;
198- expect ( allOutput ) . toContain ( "ARCH-001" ) ;
199- expect ( allOutput ) . not . toContain ( "GEN-001" ) ;
200- } ) ;
141+ const allOutput = logSpy . mock . calls
142+ . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
143+ . join ( "\n" ) ;
144+ const parsed = JSON . parse ( allOutput ) ;
145+ expect ( parsed ) . toBeInstanceOf ( Array ) ;
146+ expect ( parsed [ 0 ] . id ) . toBe ( "ARCH-001" ) ;
147+ expect ( parsed [ 0 ] . domain ) . toBe ( "architecture" ) ;
148+ } ) ;
201149
202- test ( "combines --domain and --json filters" , async ( ) => {
203- const adrsDir = join ( tempDir , ".archgate" , "adrs" ) ;
204- mkdirSync ( adrsDir , { recursive : true } ) ;
205- writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
206- writeFileSync (
207- join ( adrsDir , "GEN-001-use-conventional-commits.md" ) ,
208- ADR_CONTENT_2
209- ) ;
150+ test ( "JSON output carries identity fields only, omitting files globs" , async ( ) => {
151+ writeFileSync (
152+ join ( adrsDir , "BE-001-api-response-envelope.md" ) ,
153+ ADR_CONTENT_WITH_FILES
154+ ) ;
155+
156+ const parent = makeProgram ( ) ;
157+ await parent . parseAsync ( [ "node" , "adr" , "list" , "--json" ] ) ;
158+
159+ const allOutput = logSpy . mock . calls
160+ . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
161+ . join ( "\n" ) ;
162+ const parsed = JSON . parse ( allOutput ) ;
163+
164+ // `files`/`respectGitignore` stay out of the listing so large ADR sets
165+ // remain small enough for agents to read inline — `adr show` has the rest.
166+ expect ( Object . keys ( parsed [ 0 ] ) . toSorted ( ) ) . toEqual ( [
167+ "domain" ,
168+ "id" ,
169+ "rules" ,
170+ "title" ,
171+ ] ) ;
172+ expect ( allOutput ) . not . toContain ( "src/api/**" ) ;
173+ } ) ;
210174
211- process . chdir ( tempDir ) ;
212- const parent = makeProgram ( ) ;
213- await parent . parseAsync ( [
214- "node" ,
215- "adr" ,
216- "list" ,
217- "--domain" ,
218- "general" ,
219- "--json" ,
220- ] ) ;
221-
222- const allOutput = logSpy . mock . calls
223- . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
224- . join ( "\n" ) ;
225- const parsed = JSON . parse ( allOutput ) ;
226- expect ( parsed ) . toHaveLength ( 1 ) ;
227- expect ( parsed [ 0 ] . id ) . toBe ( "GEN-001" ) ;
228- } ) ;
175+ test ( "filters by domain with --domain flag" , async ( ) => {
176+ writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
177+ writeFileSync (
178+ join ( adrsDir , "GEN-001-use-conventional-commits.md" ) ,
179+ ADR_CONTENT_2
180+ ) ;
181+
182+ const parent = makeProgram ( ) ;
183+ await parent . parseAsync ( [
184+ "node" ,
185+ "adr" ,
186+ "list" ,
187+ "--domain" ,
188+ "architecture" ,
189+ ] ) ;
190+
191+ const allOutput = logSpy . mock . calls
192+ . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
193+ . join ( "\n" ) ;
194+ expect ( allOutput ) . toContain ( "ARCH-001" ) ;
195+ expect ( allOutput ) . not . toContain ( "GEN-001" ) ;
196+ } ) ;
229197
230- test ( "prints 'No ADRs found.' when adrs directory is empty" , async ( ) => {
231- mkdirSync ( join ( tempDir , ".archgate" , "adrs" ) , { recursive : true } ) ;
198+ test ( "combines --domain and --json filters" , async ( ) => {
199+ writeFileSync ( join ( adrsDir , "ARCH-001-use-typescript.md" ) , ADR_CONTENT_1 ) ;
200+ writeFileSync (
201+ join ( adrsDir , "GEN-001-use-conventional-commits.md" ) ,
202+ ADR_CONTENT_2
203+ ) ;
204+
205+ const parent = makeProgram ( ) ;
206+ await parent . parseAsync ( [
207+ "node" ,
208+ "adr" ,
209+ "list" ,
210+ "--domain" ,
211+ "general" ,
212+ "--json" ,
213+ ] ) ;
214+
215+ const allOutput = logSpy . mock . calls
216+ . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
217+ . join ( "\n" ) ;
218+ const parsed = JSON . parse ( allOutput ) ;
219+ expect ( parsed ) . toHaveLength ( 1 ) ;
220+ expect ( parsed [ 0 ] . id ) . toBe ( "GEN-001" ) ;
221+ } ) ;
232222
233- process . chdir ( tempDir ) ;
234- const parent = makeProgram ( ) ;
235- await parent . parseAsync ( [ "node" , "adr" , "list" ] ) ;
223+ test ( "prints 'No ADRs found.' when adrs directory is empty" , async ( ) => {
224+ const parent = makeProgram ( ) ;
225+ await parent . parseAsync ( [ "node" , "adr" , "list" ] ) ;
236226
237- const allOutput = logSpy . mock . calls
238- . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
239- . join ( "\n" ) ;
240- expect ( allOutput ) . toContain ( "No ADRs found." ) ;
227+ const allOutput = logSpy . mock . calls
228+ . map ( ( c : unknown [ ] ) => String ( c [ 0 ] ) )
229+ . join ( "\n" ) ;
230+ expect ( allOutput ) . toContain ( "No ADRs found." ) ;
231+ } ) ;
241232 } ) ;
242233
243234 test ( "exits with error when .archgate/ directory is missing" , async ( ) => {
244- process . chdir ( tempDir ) ;
245235 const parent = makeProgram ( ) ;
246236
247237 await expect ( parent . parseAsync ( [ "node" , "adr" , "list" ] ) ) . rejects . toThrow (
0 commit comments