@@ -2,20 +2,20 @@ import { describe, expect, it } from "vitest";
22import { inferScopeFromFiles , inferTicketFromBranch } from "../../src/context.js" ;
33
44describe ( "inferScopeFromFiles" , ( ) => {
5- it ( "returns the dominant top-level directory when it covers at least 60 percent " , ( ) => {
5+ it ( "returns null when top-level dirs are structural noise (src) " , ( ) => {
66 expect ( inferScopeFromFiles ( [
77 "src/cli.ts" ,
88 "src/workflow.ts" ,
99 "README.md"
10- ] ) ) . toBe ( "src" ) ;
10+ ] ) ) . toBeNull ( ) ;
1111 } ) ;
1212
13- it ( "returns null when no top-level directory reaches the threshold " , ( ) => {
13+ it ( "returns stem when source and test files share the same module name " , ( ) => {
1414 expect ( inferScopeFromFiles ( [
1515 "src/cli.ts" ,
1616 "tests/cli.test.ts" ,
1717 "README.md"
18- ] ) ) . toBeNull ( ) ;
18+ ] ) ) . toBe ( "cli" ) ;
1919 } ) ;
2020
2121 it ( "prefers configured scope mappings when they cover the threshold" , ( ) => {
@@ -27,6 +27,58 @@ describe("inferScopeFromFiles", () => {
2727 "src/cli" : "cli"
2828 } ) ) . toBe ( "cli" ) ;
2929 } ) ;
30+
31+ it ( "returns file stem for a single test file (strips .test suffix)" , ( ) => {
32+ expect ( inferScopeFromFiles ( [
33+ "tests/unit/workflow.test.ts"
34+ ] ) ) . toBe ( "workflow" ) ;
35+ } ) ;
36+
37+ it ( "returns file stem for a single spec file" , ( ) => {
38+ expect ( inferScopeFromFiles ( [
39+ "tests/unit/candidates.spec.ts"
40+ ] ) ) . toBe ( "candidates" ) ;
41+ } ) ;
42+
43+ it ( "returns parent dir when stems diverge but directory is shared" , ( ) => {
44+ expect ( inferScopeFromFiles ( [
45+ "src/api/users.ts" ,
46+ "src/api/posts.ts"
47+ ] ) ) . toBe ( "api" ) ;
48+ } ) ;
49+
50+ it ( "returns parent dir for components with diverging stems" , ( ) => {
51+ expect ( inferScopeFromFiles ( [
52+ "src/components/Button.tsx" ,
53+ "src/components/Modal.tsx"
54+ ] ) ) . toBe ( "components" ) ;
55+ } ) ;
56+
57+ it ( "falls back to parent dir when stem is index" , ( ) => {
58+ expect ( inferScopeFromFiles ( [
59+ "src/dashboard/index.ts"
60+ ] ) ) . toBe ( "dashboard" ) ;
61+ } ) ;
62+
63+ it ( "returns null when all dirs are noise and stems diverge" , ( ) => {
64+ expect ( inferScopeFromFiles ( [
65+ "tests/unit/foo.test.ts" ,
66+ "tests/unit/bar.test.ts"
67+ ] ) ) . toBeNull ( ) ;
68+ } ) ;
69+
70+ it ( "returns null for empty file list" , ( ) => {
71+ expect ( inferScopeFromFiles ( [ ] ) ) . toBeNull ( ) ;
72+ } ) ;
73+
74+ it ( "returns null when no threshold is met across scattered files" , ( ) => {
75+ expect ( inferScopeFromFiles ( [
76+ "src/cli.ts" ,
77+ "tests/cli.test.ts" ,
78+ "docs/guide.md" ,
79+ "README.md"
80+ ] ) ) . toBeNull ( ) ;
81+ } ) ;
3082} ) ;
3183
3284describe ( "inferTicketFromBranch" , ( ) => {
0 commit comments