Skip to content

Commit 04a25cc

Browse files
committed
fix(scripts): teach check-auth-mount-ledger to resolve an imported basePath default
deriveBasePath() read AuthPlugin's basePath fallback as a re-typed string literal at a fixed regex position. #16384 replaced that literal with an import of the package's single DEFAULT_AUTH_BASE_PATH definition, so the regex could no longer find a value and the gate refused (NOT MEASURED) instead of running its census. The fallback is still read from source rather than hardcoded here -- the same justification the function already carried -- just one hop further: when the fallback is a bare identifier instead of a literal, resolve it from the module that actually declares it (auth-manager.ts), which joins MOUNT_SOURCE and LEDGER_SOURCE as a third dispatch-gates-derivable input. In-place per this repo's bounded-fix exemption: same file MOUNT_SOURCE already names (so squarely dispatch-gates-derived for this same diff), mechanical (a second alternative in one regex plus a same-shape lookup), held by no other claim, and no new verification surface -- the two new self-test assertions extend an EXISTING battery's existing coverage of the existing "the base path is derived" invariant rather than opening a new one. Claude-Session: https://claude.ai/code/session_01URLHobLUJB9K1ABV6ofdjj Co-authored-by: Claude <noreply@anthropic.com>
1 parent fb6d109 commit 04a25cc

1 file changed

Lines changed: 47 additions & 11 deletions

File tree

‎scripts/check-auth-mount-ledger.mjs‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ import { isEntrypoint } from './invoked-as.mjs';
137137
// must not red. A battery BELOW its floor means cases stopped running; the
138138
// remedy is to find what stopped registering.
139139
const SELF_TEST_BATTERIES = Object.freeze({
140-
'The base path is DERIVED, and its absence is not an empty population.': 2,
140+
'The base path is DERIVED, and its absence is not an empty population.': 4,
141141
'LOAD-BEARING NEGATIVE: a mount with an exact row is clean.': 1,
142142
'LOAD-BEARING POSITIVE: a mount added with no row REDDENS, naming the route.': 2,
143143
'THE RIGHT BOUNDARY, both directions. This is the defect class #10534 fell into.': 4,
@@ -154,7 +154,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
154154
'#8435 remedy authority. PLACEMENT is pinned here, per-gate, because the': 4,
155155
'Parse anchors: a moved anchor is a REFUSAL input, never an empty population.': 2,
156156
'The escaped-quote shape the real notes use is measured, not truncated.': 1,
157-
'And the real inputs on disk are readable, so the anchors have not moved.': 2,
157+
'And the real inputs on disk are readable, so the anchors have not moved.': 3,
158158
});
159159

160160
// DELETING an entry silences that battery's floor exactly as effectively as
@@ -168,11 +168,15 @@ const UNATTRIBUTED_BATTERY = '(no battery open)';
168168

169169
const ROOT = resolve(new URL('..', import.meta.url).pathname);
170170

171-
/** The two inputs. Module-scope literals, so `dispatch-gates` derives this
172-
* family for a diff touching either of them (#10309: a gate nothing can
173-
* derive is a gate that runs only when someone remembers it). */
171+
/** The three inputs. Module-scope literals, so `dispatch-gates` derives this
172+
* family for a diff touching any of them (#10309: a gate nothing can
173+
* derive is a gate that runs only when someone remembers it).
174+
* [#16384] `AUTH_MANAGER_SOURCE` joined the set the day the `basePath`
175+
* fallback in `MOUNT_SOURCE` stopped being a re-typed literal and became an
176+
* identifier declared over there instead — see `deriveBasePath`. */
174177
const MOUNT_SOURCE = 'packages/plugins/plugin-auth/src/auth-plugin.ts';
175178
const LEDGER_SOURCE = 'packages/plugins/plugin-auth/src/auth-route-ledger.ts';
179+
const AUTH_MANAGER_SOURCE = 'packages/plugins/plugin-auth/src/auth-manager.ts';
176180

177181
export const EXIT_CLEAN = 0;
178182
export const EXIT_FINDINGS = 1;
@@ -230,11 +234,26 @@ const LANE_VERBS = new Set(['all', 'use']);
230234
/**
231235
* The auth base path, DERIVED from the plugin rather than re-typed here, so a
232236
* rename moves this gate with it instead of silently emptying its population.
237+
*
238+
* [#16384] The fallback used to be a re-typed string literal at this exact
239+
* spot; it is now the package's single `DEFAULT_AUTH_BASE_PATH` definition,
240+
* imported from `auth-manager.ts` rather than retyped in the plugin. The
241+
* literal-string match stays first (still the shape of every OTHER fallback
242+
* this gate might meet); when the fallback is a bare identifier instead,
243+
* resolve it the same way this function was already justified — one hop
244+
* through the module that actually DECLARES it, never a second hardcoded
245+
* copy — via `importedSource`, the text of the module the plugin imports the
246+
* identifier from.
233247
*/
234-
export function deriveBasePath(mountSource) {
248+
export function deriveBasePath(mountSource, importedSource) {
235249
const masked = maskComments(mountSource);
236-
const m = /basePath\s*=\s*this\.options\.basePath\s*(?:\|\||\?\?)\s*'([^']+)'/.exec(masked);
237-
return m ? m[1] : null;
250+
const m =
251+
/basePath\s*=\s*this\.options\.basePath\s*(?:\|\||\?\?)\s*(?:'([^']+)'|([A-Za-z_$][\w$]*))/.exec(masked);
252+
if (!m) return null;
253+
if (m[1] != null) return m[1];
254+
if (importedSource == null) return null;
255+
const decl = new RegExp(`export const ${m[2]}\\s*=\\s*'([^']+)'`).exec(maskComments(importedSource));
256+
return decl ? decl[1] : null;
238257
}
239258

240259
/**
@@ -627,6 +646,20 @@ function selfTest() {
627646
battery('The base path is DERIVED, and its absence is not an empty population.');
628647
ok(deriveBasePath(FIXTURE_PREAMBLE) === FIXTURE_BASE, 'basePath was not derived from the plugin');
629648
ok(deriveBasePath('const basePath = 42;') === null, 'a plugin with no derivable basePath did not refuse');
649+
// [#16384] The fallback is now a named identifier import in the real plugin,
650+
// not a re-typed literal — resolved one hop through the module it is
651+
// DECLARED in, never guessed at.
652+
ok(
653+
deriveBasePath(
654+
"const basePath = this.options.basePath || DEFAULT_AUTH_BASE_PATH;\n",
655+
"export const DEFAULT_AUTH_BASE_PATH = '/api/v1/auth';\n",
656+
) === FIXTURE_BASE,
657+
'an identifier fallback was not resolved through the imported module',
658+
);
659+
ok(
660+
deriveBasePath("const basePath = this.options.basePath || DEFAULT_AUTH_BASE_PATH;\n") === null,
661+
'an identifier fallback resolved to something without an imported module to read',
662+
);
630663

631664
// -- LOAD-BEARING NEGATIVE: a mount with an exact row is clean.
632665
battery('LOAD-BEARING NEGATIVE: a mount with an exact row is clean.');
@@ -895,7 +928,7 @@ function selfTest() {
895928

896929
// -- And the real inputs on disk are readable, so the anchors have not moved.
897930
battery('And the real inputs on disk are readable, so the anchors have not moved.');
898-
for (const rel of [MOUNT_SOURCE, LEDGER_SOURCE]) {
931+
for (const rel of [MOUNT_SOURCE, LEDGER_SOURCE, AUTH_MANAGER_SOURCE]) {
899932
ok(existsSync(join(ROOT, rel)), `${rel} does not exist -- this gate's anchor moved`);
900933
}
901934

@@ -981,14 +1014,17 @@ function main() {
9811014

9821015
const mountAbs = join(ROOT, MOUNT_SOURCE);
9831016
const ledgerAbs = join(ROOT, LEDGER_SOURCE);
1017+
const authManagerAbs = join(ROOT, AUTH_MANAGER_SOURCE);
9841018
if (!existsSync(mountAbs)) refuse(`${MOUNT_SOURCE} does not exist`);
9851019
if (!existsSync(ledgerAbs)) refuse(`${LEDGER_SOURCE} does not exist`);
1020+
if (!existsSync(authManagerAbs)) refuse(`${AUTH_MANAGER_SOURCE} does not exist`);
9861021

9871022
const mountText = readFileSync(mountAbs, 'utf8');
9881023
const ledgerText = readFileSync(ledgerAbs, 'utf8');
1024+
const authManagerText = readFileSync(authManagerAbs, 'utf8');
9891025

990-
const basePath = deriveBasePath(mountText);
991-
if (!basePath) refuse(`no \`basePath\` default could be derived from ${MOUNT_SOURCE}`);
1026+
const basePath = deriveBasePath(mountText, authManagerText);
1027+
if (!basePath) refuse(`no \`basePath\` default could be derived from ${MOUNT_SOURCE} (or its import from ${AUTH_MANAGER_SOURCE})`);
9921028

9931029
const rows = parseLedgerRows(ledgerText);
9941030
if (rows === null) refuse(`the AUTH_ROUTE_LEDGER anchor was not found in ${LEDGER_SOURCE}`);

0 commit comments

Comments
 (0)