1616REPO = Path (__file__ ).resolve ().parents [2 ]
1717RUNTIME = REPO / "boatstack"
1818CONFIG = REPO / "project.example.json"
19- DOMAIN_NEUTRAL_PATTERN = re . compile (
20- r"\b(?:git|repository|worktree|branch| pull request|coding agent|publication )\b" ,
21- re .IGNORECASE ,
22- )
19+ DOMAIN_NEUTRAL_WORDS = { "git" , "repository" , "worktree" , "branch" , "publication" }
20+ DOMAIN_NEUTRAL_PHRASE = re . compile ( r"\b(?:pull\s+ request|coding\s+ agent)\b" , re . IGNORECASE )
21+ GO_IDENTIFIER = re .compile ( r"[A-Za-z_][A-Za-z0-9_]*" )
22+ GO_IDENTIFIER_PART = re . compile ( r"[A-Z]?[a-z]+|[A-Z]+(?![a-z])|[0-9]+" )
2323
2424
2525def go_source_metadata (paths : list [Path ]) -> list [dict [str , object ]]:
@@ -43,8 +43,18 @@ def go_source_metadata(paths: list[Path]) -> list[dict[str, object]]:
4343def domain_vocabulary_hits (paths : list [Path ]) -> list [tuple [Path , str ]]:
4444 hits : list [tuple [Path , str ]] = []
4545 for path in paths :
46- for match in DOMAIN_NEUTRAL_PATTERN .finditer (path .read_text ()):
46+ source = path .read_text ()
47+ for match in DOMAIN_NEUTRAL_PHRASE .finditer (source ):
4748 hits .append ((path , match .group (0 ).lower ()))
49+ for identifier in GO_IDENTIFIER .findall (source ):
50+ if identifier .lower () == "github" :
51+ continue
52+ parts = [
53+ part .lower ()
54+ for component in identifier .split ("_" )
55+ for part in GO_IDENTIFIER_PART .findall (component )
56+ ]
57+ hits .extend ((path , part ) for part in parts if part in DOMAIN_NEUTRAL_WORDS )
4858 return hits
4959
5060
@@ -430,8 +440,15 @@ def test_general_kernel_is_domain_neutral_and_owns_shared_control_laws(self) ->
430440 self .assertEqual ([], domain_vocabulary_hits (kernel_files ))
431441 with tempfile .TemporaryDirectory () as temporary :
432442 fixture = Path (temporary ) / "domain_leak_test.go"
433- fixture .write_text ('package kernel\n const fixtureDomain = "pull request"\n ' )
434- self .assertEqual ([(fixture , "pull request" )], domain_vocabulary_hits ([fixture ]))
443+ for source , token in (
444+ ('package kernel\n const fixtureDomain = "pull request"\n ' , "pull request" ),
445+ ("package kernel\n type gitClient struct{}\n " , "git" ),
446+ ("package kernel\n var testRepository string\n " , "repository" ),
447+ ("package kernel\n type worktreeManager struct{}\n " , "worktree" ),
448+ ):
449+ with self .subTest (token = token ):
450+ fixture .write_text (source )
451+ self .assertEqual ([(fixture , token )], domain_vocabulary_hits ([fixture ]))
435452
436453 boatstack_packages = "github.com/operatorstack/boatstack/boatstack/"
437454 kernel_package = boatstack_packages + "kernel"
0 commit comments