Skip to content

Core: harden codebase - #5

Merged
Fellmonkey merged 83 commits into
mainfrom
fix/codebase-hardening
Nov 26, 2026
Merged

Fellmonkey merged 83 commits into
mainfrom
fix/codebase-hardening

Conversation

@Fellmonkey

@Fellmonkey Fellmonkey commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

What this changes and why

One change: harden the DomainCraft compiler and CLI contract. A full read-only review produced 234 findings; 175 are fixed here. The four left open are documented decisions (explicit permission-operation list, set type, two separate TTL policies, local untracked artifacts). The branch is three signed commits; the final tree is byte-identical to the reviewed state.

Core — specmeta owns field kinds, relation types, index keys and defaults. Parser, validator, IR and renderer use one table per vocabulary instead of parallel switches. Every bugfix has a regression check named in compliance-suite/regressions.tsv. Contract version is v2: IR helpers are IsUuid/IsJson/IsJsonB; uppercase aliases are gone and all bundled bridges declare contract_version: 2.

Bridges and caches — corrupt metadata fails closed; unrelated local paths never become GitHub clones; release redirects reject credentials and internal targets; git environment is scrubbed. One redaction rule, one bounded HTTP client, one atomic-write helper, one path-normalization key.

Renderer and migrations — when: conditions come from one table; staging steps are named without changing their order; helper templates are helpers.*.tmpl and embed with one directive. Migration plans use the canonical column names recorded in snapshot.json: a relation field's column is category_id, not category. Shadowed and chained renames no longer suppress or mis-target RenameColumn. Cleanup opens roots through one withRoot helper.

CLI — flag syntax and --admin arguments are validated before rendering; community-command consent is decided before files are written. Child-process output is sanitized; WASM arguments are type-checked; refactoring reports go to stderr so stdout stays usable. bridges --check-updates is sequential and deterministic.

CI — actions pinned to Node 24-based majors, verify job gates tag pushes, tck.yml uses block-style with: mappings (flow mapping with ${{ }} was invalid YAML), bench.yml copies the PR Makefile into the base worktree so make bench works against older commits. CLAUDE.md now records the measured benchmark rule and these CI traps.

Fixes # — none. The findings came from a review on this branch; no separate issue was opened.

How you tested it

go vet ./...                                        clean
go test ./...                                       all packages pass
go test -race -count=1 -shuffle=on ./...            pass
go test -tags=integration ./internal/bridge         pass
golangci-lint run ./...                             0 issues
govulncheck ./...                                   no vulnerabilities
make check-tidy                                     clean
schema-gen to temp + diff spec/domain.schema.json   clean
python yaml.safe_load on .github/workflows/*.yml    all four parse
benchstat base vs head (SortEntities/BuildHubRelations)
  toposort simplification: +2884% fanout/2000       reverted, reason in code
  restored algorithm: only run-to-run noise

Real CLI run on a fresh binary, not a unit test:

domaincraft init --scenario shop --name "Smoke Shop"   domain.yaml, 5 entities
domaincraft validate                                   Schema valid (5 entities)
generate --bridge bridges/csharp/transport/rest --admin
                                                       96 C# files + 14 admin files
generate --bridge bridges/typescript/react             12 files, extends chain intact
generate --prune with title -> name [old_name:title]
  and int -> bigint                                    type/rename reports on stderr,
                                                        best-effort DB warning, snapshot updated

Tested on: local, Windows, Go 1.27.4.

Merge Danger

Door: mostly two-way; contract v2 and the helper-template rename are the one-way parts for external bridges.

Blast Radius: generated code and bridge templates. A community bridge using the removed uppercase IR helpers or a _helpers.*.tmpl filename needs a template update. Rolling back means reverting three commits and rebuilding the binary; no generated project is changed by the merge itself.

How you found it

  • I use DomainCraft and ran into this myself
  • I found it by reading the code or comparing with other compilers
  • Someone else reported it (link the issue above)

AI tools used to write this change: yes — an OpenCode agent read the code, ran tests and benchmark comparisons, drafted the fixes, and drafted this PR text. The human author verified every change and owns the PR.

Checklist

  • Commits are signed and verified (GitHub shows "Verified")
  • The author of this PR is a person; an AI agent is not the contributor (see CONTRIBUTING.md → Pull requests)
  • make lint and make test pass; make fmt was skipped to preserve the CRLF working tree
  • Deterministic output: contract and golden tests pin sorted generation
  • Every bugfix has a regression check named in compliance-suite/regressions.tsv

@Fellmonkey
Fellmonkey force-pushed the fix/codebase-hardening branch from 6f66474 to 5cd6954 Compare November 24, 2026 18:48
@Fellmonkey Fellmonkey changed the title Core: harden codebase (#5) Core: harden codebase Nov 24, 2026
- reject non-integral float seed values for integral fields
- validate entity old_name as identifier and reject self-reference
- fail on duplicate features instead of collapsing them silently
- split validateField into focused rule helpers
- register the new regression checks
…sions

- reject unknown when conditions when loading a bridge manifest
- alias the contract version to specmeta and drop bare literals
- keep a resolved package version when the cache write fails
- deduplicate the version cache pipeline
- reject oversized NuGet responses instead of truncating them
- report rollback failures instead of swallowing them
- keep existing permissions when AtomicWrite rewrites a file
- export ir.TableNameFor and reuse it in the migration plan
- unify casing variants for content and path rewrites
- deduplicate the existing-file filter
- assert byte-identical snapshot output
- make lint runs the pinned golangci-lint; vet stays separate
- make build no longer rewrites go.mod/go.sum
- CI cross-compiles the js/wasm validator and shuffles tests
- bridges CI runs the hermetic TypeScript TCK halves
- document consent flags, real bridge chains and C#-only rename artifacts
- alias CoreContractVersion to specmeta and dedupe embedded path helpers
- reject unsafe branch names from cache metadata before git fetch
- join fetch, reset, cleanup and re-clone errors
- share the monorepo upward walk between resolvers
- --prune returns cleanup failures instead of advancing the snapshot
- check chmod and report rename/restore errors during self-update
- route progress and warnings through the logger
- strip terminal controls from displayed bridge commands
- bundle migration context and add prune orchestration tests
- record key presence for numeric config blocks instead of testing value == 0
- apply defaults only to omitted keys
- accept explicit zeros in validator while still rejecting negatives
- cover YAML merges and strict unknown-key behavior
JWT auth now needs a resolvable entity and at least one role. Range
validators cover gte/lte, gt/lt and numeric min/max; invalid string
bounds and defaults are errors. Unterminated modifier lists and keys
smuggled through YAML merges no longer pass strict decoding.
Prune rewrites preserve invalid UTF-8 bytes in developer-owned files.
Namespace detection no longer assumes C# syntax. Scaffold-once targets
are staged once per render. Test seams and the app-dir override are
protected against races.
Pinned refs with slashes resolve correctly. A cache checkout without
proof of ownership is rejected; the contract gate checks the pinned ref.
Git children get a deadline. Cache read errors and version parse errors
are no longer masked. Cycle detection honours filesystem case rules.
Local builds stamp the version only from an exact tag. Invalid flag
values exit 2; migration diagnostics go to stderr. Unknown addons warn.
Tool versions live in the Makefile, and CI and release use the same
gates as local runs.
@Fellmonkey
Fellmonkey force-pushed the fix/codebase-hardening branch from e9aef15 to 4834795 Compare November 25, 2026 23:01
Specmeta is the single source for field kinds, relation types and defaults. Parser, validator, IR and renderer share tables and predicates. Bundled bridges declare contract v2 and embed helper templates without explicit directives.
Fail closed on corrupt cache metadata and redirects. Share remote/path primitives, atomic writes and root lifetimes. Migration diffs share name resolution and carry canonical column names.
Fail-fast consent and argument checks, sanitized child output and WASM inputs, reports on stderr, shared toolchain and benchmark commands, and a regression table entry per bug fix.
@Fellmonkey
Fellmonkey force-pushed the fix/codebase-hardening branch from 4faf39e to d9b0fc0 Compare November 26, 2026 19:06
@Fellmonkey
Fellmonkey merged commit 8927417 into main Nov 26, 2026
11 checks passed
@Fellmonkey
Fellmonkey deleted the fix/codebase-hardening branch November 26, 2026 19:18
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