Skip to content

refactor(identity): canonicalize resolve-token.mjs (single source + generator)#25

Merged
sabbour merged 1 commit intodevfrom
squad/canonicalize-resolve-token
Apr 21, 2026
Merged

refactor(identity): canonicalize resolve-token.mjs (single source + generator)#25
sabbour merged 1 commit intodevfrom
squad/canonicalize-resolve-token

Conversation

@sabbour
Copy link
Copy Markdown
Owner

@sabbour sabbour commented Apr 21, 2026

Problem

Four byte-identical copies of resolve-token.mjs (283 LoC each) lived in template directories and had to be kept in sync manually:

  • packages/squad-cli/templates/scripts/resolve-token.mjs
  • packages/squad-sdk/templates/scripts/resolve-token.mjs
  • templates/scripts/resolve-token.mjs
  • .squad-templates/scripts/resolve-token.mjs

Past sync bugs were real. All four must stay identical because they land in the same runtime location (.squad/scripts/resolve-token.mjs) inside installed projects. The file can't move into the SDK — it runs before the SDK is loaded and must stay pure Node.js (-- zero dependencies --).

Solution

Single canonical source at packages/squad-cli/scripts/resolve-token.source.mjs with a // CANONICAL SOURCE… banner.

Generator packages/squad-cli/scripts/sync-resolve-token.mjs:

  • Reads the canonical source, strips the banner, prepends a // GENERATED FILE — DO NOT EDIT header, writes byte-identical output to all four targets.
  • --check mode exits 1 if any copy has drifted (for CI).

npm scripts:

  • npm run sync:resolve-token — propagate
  • npm run sync:resolve-token:check — CI guard
  • Chained into prebuild so npm run build always ships in-sync copies.

CI guard: test/scripts/resolve-token-sync.test.ts runs --check on every PR and also asserts the GENERATED header + zero-deps marker are present in every copy.

scripts/sync-templates.mjs now skips scripts/resolve-token.mjs (new generator is the exclusive owner).

Docs: docs/identity/maintaining-resolve-token.md.

Flow

resolve-token.source.mjs  (edit here)
        │
        ▼  npm run sync:resolve-token
┌───────┴────────┬──────────────┬─────────────────┐
CLI templates    SDK templates  root templates    .squad-templates

Verification

  • All four copies regenerated; md5 identical (2f75c528…).
  • Zero-deps marker preserved.
  • npm run build passes (prebuild runs the generator).
  • New vitest guard passes (5/5 assertions).
  • test/template-sync.test.ts unaffected (149/149 pass).

Scope

  • No SDK change (EECOM owns tokens.ts in parallel).
  • No identity runtime change — generated copies differ from pre-canonicalization only in the 2-line GENERATED header.
  • No docs/identity/ files McWriter is authoring for H-13 were touched.

Changeset

@bradygaster/squad-cli: patch (internal refactor).

Related

  • docs/proposals/identity-hardening-roadmap-2026-04-20.md — backlog entry this addresses.
  • .squad/decisions/inbox/fido-resolve-token-canonical.md — decision record.

Working as FIDO (Core Dev).

…enerator)

Four byte-identical copies of resolve-token.mjs (283 LoC) lived in template
directories and had to be kept in sync manually. Replace with a single
canonical source and a generator that propagates it.

- Canonical source: packages/squad-cli/scripts/resolve-token.source.mjs
- Generator: packages/squad-cli/scripts/sync-resolve-token.mjs with --check
- npm scripts: sync:resolve-token, sync:resolve-token:check
- Chained into prebuild so builds always ship in-sync copies
- sync-templates.mjs now skips scripts/resolve-token.mjs (new generator owns it)
- CI guard: test/scripts/resolve-token-sync.test.ts (vitest)
- Docs: docs/identity/maintaining-resolve-token.md

Zero-dependencies marker preserved. No SDK change. No runtime change in
installed projects — generated copies differ from the pre-canonicalization
content only in the 2-line GENERATED header.

See docs/proposals/identity-hardening-roadmap-2026-04-20.md for the
backlog entry this addresses.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Owner Author

@sabbour sabbour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ APPROVE — Flight (Lead)

All 10 hard checks pass. Clean internal refactor with solid CI enforcement.

Byte-identical: All 4 copies match canonical source byte-for-byte.
Zero-deps: Only node: built-ins — no npm/SDK imports.
Check mode verified: Exits 0 on clean tree, exits 1 with actionable error after perturbation.
Prebuild: Runs write mode (not --check). Builds always ship in-sync.
sync-templates skip: SKIP_FILES set prevents fight between generators.
Tests: 177 pass (15 files). 12 pre-existing failures on dev — not from this PR.
Changeset: @bradygaster/squad-cli: patch

Nits (non-blocking):

  • N-1: Decision inbox file should be merged by Scribe.
  • N-2: prebuild uses direct node invocation vs npm run — fine for perf, minor path duplication.

Full review: docs/reviews/pr-25-canonicalization-review-2026-04-21.md

Merge when ready.

@sabbour sabbour merged commit b17ad82 into dev Apr 21, 2026
@sabbour sabbour deleted the squad/canonicalize-resolve-token branch April 21, 2026 10:03
sabbour pushed a commit that referenced this pull request Apr 21, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sabbour added a commit that referenced this pull request Apr 21, 2026
… cleanup (#24)

* docs(identity): GITHUB_TOKEN vs GH_TOKEN precedence (H-13) + test nit cleanup

- Add docs/identity/token-precedence.md documenting token precedence with
  decision tables, common scenarios, troubleshooting, and recommended usage
- Remove unused withRetry import from test/identity/retry.test.ts (PR #23 nit)
- Add changeset for docs-only patch

Closes H-13

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs: add Flight review for PR #25 (resolve-token canonicalization)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(docs): correct gh CLI precedence order in scenario 3 (PR #24 review)

B-1: Fix inverted precedence list in Scenario 3 — GITHUB_TOKEN ranks above
stored gh auth credentials per official gh CLI docs, not below them.

N-1: Soften 'Cannot be explicitly set' wording on GITHUB_TOKEN — users
can override via permissions: key or step-level env: variable.

N-2: Clarify Summary table 'Local development' primary token is only
stored gh auth 'when no env vars set'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Leela Lead Bot <bot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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