refactor(core,cli,engine): apply /simplify findings on getVariables PR

- core/runtime/getVariables.ts: collapse the noisy three-step type-guard
  re-cast into a single `Record<string, unknown>` narrow with early-continue
  guards. Same behaviour, ~6 lines shorter.
- cli/commands/render.ts: separate VariablesParseError from UI strings.
  parseVariablesArg now returns a kind-discriminated error
  (`conflict | read-error | parse-error | shape-error`) and the wrapper
  resolveVariablesArg owns the title/message mapping via
  `variablesErrorMessage`. Keeps the parser pure of presentation strings.
- cli/commands/render.test.ts: lift the `await import("./render.js")` into
  a `beforeAll`, add a typed `expectErr` helper, assert on the structured
  error kind instead of message-string regexes. Same coverage, less noise.
- engine/services/frameCapture.ts: replace the `as unknown as { ... }`
  double-cast with a single named `WindowWithVariables` alias inside the
  page closure.

All affected suites green (core getVariables 9, cli render 12, cli
dockerRunArgs 13).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
James
2026-05-03 00:24:03 +00:00
co-authored by Claude Opus 4.7
parent c0d75a5268
commit 8c8dd6ad0c
4 changed files with 105 additions and 70 deletions
+4 -8
View File
@@ -38,14 +38,10 @@ function readDeclaredDefaults(root: Element | null): Record<string, unknown> {
const out: Record<string, unknown> = {};
for (const entry of parsed) {
if (
entry &&
typeof entry === "object" &&
typeof (entry as { id?: unknown }).id === "string" &&
"default" in entry
) {
out[(entry as { id: string }).id] = (entry as { default: unknown }).default;
}
if (!entry || typeof entry !== "object") continue;
const e = entry as Record<string, unknown>;
if (typeof e.id !== "string" || !("default" in e)) continue;
out[e.id] = e.default;
}
return out;
}