Skip to content

feat: Spring Boot archmind.json guards; visualize ignoreFindings; parse errors and files over 32 KiB - #14

Merged
Kidkender merged 5 commits into
mainfrom
feat/springboot-user-config
Nov 13, 2026
Merged

Kidkender merged 5 commits into
mainfrom
feat/springboot-user-config

Conversation

@Kidkender

@Kidkender Kidkender commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Three changes, one commit each. Merge after #12 for a green CI build.

Changes

  • visualize honours ignoreFindings (c3bcd75). archmind visualize called explain() without options, so finding types listed in archmind.json ignoreFindings still showed in the HTML report. It now passes { ignore }, like archmind findings. nestjs-parser drops its private copy of loadUserConfig and uses the one in @kidkender/archmind-protocol (same behaviour; requires protocol ^0.5.1).

  • Spring Boot reads archmind.json guards (8a90e63). The adapter never loaded the user config. Annotation names under guards.auth_gate now emit ir:auth_gate, names under guards.authz_check emit ir:auth_gate → ir:authz_check; the config wins over the built-in rules (a listed Shiro @RequiresRoles is no longer ir:unknown_middleware). Also updates docs/next-version-ideas.md to match v0.9.1.

  • Parse failures are reported, and files over 32 KiB are parsed (27a0dde). laravel-parser and springboot-parser wrapped readFileSync and tree-sitter's parse() in one bare catch { return <empty> }. That also hid a real bug: tree-sitter 0.21 throws "Invalid argument" past its default 32 KiB buffer and only route-parser passed a bufferSize, so controllers and services larger than 32 KiB produced no auth, transaction, isolation or guard nodes. All read+parse sites now go through php-source.ts / java-source.ts: an unreadable file yields nothing as before, the buffer is sized to the source, and a parse failure is printed on stderr with the file path.

  • Compare tree-sitter nodes by position (ff7a102). gatherServiceCalls skipped an already-folded relationship accessor with child !== objNode; tree-sitter 0.21 does not always return the same JS object for the same node (node cache + GC), so some runs emitted a duplicate service call (User::apiTokens next to User::apiTokens()->delete). Output varied between identical runs (koel 1943 / 1946 / 1943 nodes) — on main too — and the parse cache below made BookStack consistently wrong. Now compared by start/end index and type; koel 1933 and BookStack 3917 on every run. Needed together with the parse cache.

  • Parse each file once per run (de35447). Parsing the large files exposed a cost small files hid: every module re-parsed the controller or service for every route, and every method lookup walked the whole tree through .children. On invoiceninja the CLI ran for over 10 minutes and the machine ran out of memory. Parsed files are now reused while their content is unchanged (32-file LRU), the five identical findMethod copies are replaced by one that uses descendantsOfType with a per-tree index, and extractUseMap is computed once per tree.

Verified

  • Build and tests of the touched packages pass (springboot-parser, nestjs-parser, laravel-parser 291/291, CLI). New tests: Spring Boot guards (with / without / malformed config), a ~40 KB Laravel controller and a ~40 KB Spring controller, the parse cache, findMethod, and a 60-run repeat of the koel folding pattern (fails on the old comparison).
  • Real projects (the five Laravel apps of the README benchmark, shallow clones):
    • koel: app/Repositories/SongRepository.php (> 32 KiB) is now read — its queries show up on 31 routes.
    • invoiceninja (58 app files > 32 KiB, 8 controllers): completes in 22 s (139 s on main, which skipped those files); +372 nodes, transactions 2 → 5. InvoiceController's 19 routes: 261 parses → 20, 6.2 s → 0.8 s, 517 MB → 20 MB.
    • monica, akaunting: graphs identical to main. No parse-failure warnings on any of the five.
  • Determinism: same build, three runs each — koel 1933 and BookStack 3917 every time (before ff7a102 they varied between runs, on main as well).
  • Spring Boot guards on RuoYi (Shiro): declaring RequiresPermissions / RequiresRoles turns 157 ir:unknown_middleware into auth gate + authorization check; exposed_read_endpoint 63 → 23. SpringBlade / RuoYi graphs otherwise identical to main.
  • visualize + ignoreFindings on RuoYi: main still lists the ignored exposed_read_endpoint 63 times in the HTML report, this branch 0 times.

…ig reader

- `archmind visualize` passed no options to explain(), so finding types listed
  in archmind.json `ignoreFindings` still appeared in the HTML report. It now
  reads the config and passes `{ ignore }`, like `archmind findings`.
- nestjs-parser drops its private copy of loadUserConfig and uses the one in
  @kidkender/archmind-protocol (same behavior); requires protocol ^0.5.1.
…tions

The Spring Boot adapter never loaded archmind.json, so `guards` had no effect
on Spring Boot projects. It now reads the config through loadUserConfig:
annotation names under `guards.auth_gate` emit ir:auth_gate, names under
`guards.authz_check` emit ir:auth_gate -> ir:authz_check. The config wins over
the built-in rules, so a listed Shiro `@RequiresRoles` is no longer
ir:unknown_middleware. A malformed archmind.json is ignored. Requires
protocol ^0.5.1.

docs: bring next-version-ideas.md in line with v0.9.1 (benchmark CLI, graph
diff, CI and lens shipped; modular Laravel partial; new items #10 and #11;
reordered priorities).
…e files over 32 KiB

Every parser wrapped readFileSync and tree-sitter's parse() in one bare
`catch { return <empty> }`, so a parse failure read as "this file has nothing
in it". That also hid a real bug: tree-sitter 0.21 throws "Invalid argument"
for input past its default 32 KiB buffer, and only route-parser passed a
bufferSize, so controllers and services larger than 32 KiB silently produced
no auth, transaction, isolation or guard nodes.

All read+parse sites now go through php-source.ts / java-source.ts:
- an unreadable file (missing, a directory, no access) yields nothing, as before
- the parse buffer is sized to the source
- a parse failure is printed on stderr with the file path and the file is skipped

Catches around JSON.parse of composer.json / archmind.json and readdirSync are
unchanged. The pass-level catches in graph-augmenter.ts are left for later.
…hole trees per lookup

Parsing files over 32 KiB (previous commit) exposed a cost that small files
hid: every module (controller, transaction, isolation, guard clause, audit log)
re-parsed the controller or service for every route, and each method lookup
walked the whole tree through `.children`, which builds a JS array at every
node. On invoiceninja the CLI ran for over 10 minutes and the machine ran out
of memory; 19 routes of InvoiceController alone took 6.2 s and 517 MB.

- php-source: parsed files are reused while their content is unchanged (up to
  32 files, least recently used dropped; an edited file is parsed again).
- findMethod is shared by the five modules (their identical private copies are
  removed) and uses descendantsOfType, with a per-tree name index.
- extractUseMap is computed once per tree (callers get a copy).

InvoiceController's 19 routes: 261 parses → 20, 6.2 s → 0.8 s, 517 MB → 20 MB,
same 196 nodes. Full invoiceninja: completes in 36 s (139 s before the 32 KiB
fix, when its large files were skipped). monica and akaunting graphs are
identical before and after.
gatherServiceCalls folds a mutating call into the relationship accessor it is
chained on ($user->apiTokens()->delete() → one "User::apiTokens()->delete")
and skips the accessor when recursing with `child !== objNode`. tree-sitter
0.21 does not always return the same JS object for the same node — it depends
on its node cache and on garbage collection — so in some runs the accessor was
visited again and emitted as a duplicate service call. That made output vary
between identical runs (koel: 1943 / 1946 / 1943 nodes; one koel method gave
two different results in 6 of 50 calls) and, with the parse cache of the
previous commit, made BookStack consistently wrong (3922 instead of 3917).

Nodes are now compared by start/end index and type. Same build, three runs:
koel 1933 and BookStack 3917 every time. New test repeats the koel pattern 60
times; it fails on the old comparison.
@Kidkender Kidkender mentioned this pull request Nov 13, 2026
@Kidkender
Kidkender merged commit 430fe31 into main Nov 13, 2026
1 check failed
@Kidkender
Kidkender deleted the feat/springboot-user-config branch November 13, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant