Skip to content

fix(import): narrow unknown error body in wordpress-plugin source (#1053) - #1075

Closed
ascorbic wants to merge 2 commits into
mainfrom
fix/1053-public-source-types
Closed

ascorbic wants to merge 2 commits into
mainfrom
fix/1053-public-source-types

Conversation

@ascorbic

Copy link
Copy Markdown
Member

What does this PR do?

Closes #1053.

Fixes the one real type error #1053 reported, and adds a regression guard so the whole class can't ship again.

The reporter's two errors, re-triaged:

  • byline.ts:204 (TS2345 kysely Transaction→Kysely) — a TypeScript 5.x variance behaviour. It does not reproduce on TypeScript 6 and is already resolved by the TS6 upgrade in chore: upgrade to TypeScript 6 + pin tsgo beta + fix dual-load config #1074 (merged). No code change needed.
  • wordpress-plugin.ts (TS18046 'error' is of type 'unknown') — real. The analyze-endpoint error body from response.json() is unknown under @cloudflare/workers-types and was read without narrowing. This file ships as raw source via the emdash/routes/* export, so it fails strict consumer typechecks. Fixed with assertion-free narrowing (clean under both the consumer's Workers-typed config and emdash's own astro/client typecheck; no as, no lint warning, runtime unchanged).

The reporter's premise was right, their repro was wrong. Bare import "emdash" resolves to compiled dist/*.d.mts and skipLibCheck covers it — verified clean. The errors only surface through the source-exported subpaths (emdash/routes/*, emdash/ui, emdash/api/*, emdash/auth/providers/*), which ship raw .ts that skipLibCheck cannot skip. Our own pnpm typecheck misses this: it runs tsgo against our lenient tsconfig (excludes src/astro/**, no Workers types). A strict consumer on real tsc deployed to Workers sees a different program.

Regression guard (scripts/typecheck-public-source.mjs + fixtures/public-types/): reconstructs the consumer view — real tsc, @cloudflare/workers-types, emdash/locals — over every .ts/.tsx source-exported subpath, and compares per-(file, errorCode) diagnostic counts to a committed baseline (same idea as the perf query-count snapshot). Wired into the CI typecheck job.

  • The .astro / virtual:emdash/* (allowlisted) module-resolution surface is the documented boundary — a hermetic type-only harness can't resolve it; real sites do, via astro check (covered by the demo/template typecheck jobs). node_modules/ diagnostics are dropped (third-party, unstable pnpm-store paths).
  • Hard sanity gates make every degenerate tsc outcome fail loudly (unexpected exit code, unparseable error lines / format drift, exit-0-with-errors, path-rooting drift) — the guard can't silently pass.
  • A hardcoded Type errors in emdash 0.12.0 under strict TypeScript #1053 sentinel asserts wordpress-plugin.ts TS18046 never returns, independent of the baseline file. TDD-verified: reverting the fix makes the harness FAIL naming exactly that error; restored → green.
  • The 23 baseline groups are pre-existing strict-consumer debt (implicit-any, ui.ts/astro-portabletext, dual-package Kysely realm, Locals.tokenScopes, import payload shapes). Tracked separately and burned down incrementally; the harness fails on any growth or new shipped-source error, shrinking as debt is fixed.

Built on #1074 (TS6). Adversarially reviewed twice (the narrowing fix and the harness); review found four false-pass/flaky vectors in the harness, all fixed before this PR (exit/parse sanity gates, count-based baseline, node_modules exclusion, tightened virtual allowlist).

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes (PR adds 0 diagnostics; repo baseline of 38 unchanged)
  • pnpm test passes (or targeted tests for my change) — the harness itself is the regression test (TDD red/green proven via the Type errors in emdash 0.12.0 under strict TypeScript #1053 sentinel); the one-line narrowing has no behavioural change to unit-test
  • pnpm format has been run
  • I have added/updated tests for my changes — the public-source typecheck harness is the regression guard for Type errors in emdash 0.12.0 under strict TypeScript #1053 and the whole shipped-source class
  • User-visible strings in the admin UI are wrapped for translation (if applicable) — N/A
  • I have added a changeset — emdash patch for the wordpress-plugin narrowing fix
  • New features link to an approved Discussion — N/A (not a feature)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.7

)

Closes #1053.

- wordpress-plugin.ts: the analyze-endpoint error body from response.json()
  is unknown under @cloudflare/workers-types; narrow it before reading
  .message instead of accessing it on unknown (TS18046). Runtime behaviour
  unchanged. (#1053 error 1, the kysely Transaction variance, was a TS5.x
  behaviour resolved by the TS6 upgrade in the base PR.)
- Add the public-source typecheck harness: fixtures/public-types reproduces
  the strict-consumer view (real tsc, @cloudflare/workers-types,
  emdash/locals) over every .ts/.tsx source-exported subpath;
  scripts/typecheck-public-source.mjs compares per-(file,code) diagnostic
  counts to a committed baseline, with hard sanity gates and a hardcoded
  #1053 sentinel. Wired into the CI typecheck job.
- The 23 baseline groups are pre-existing strict-consumer debt, tracked
  separately; the harness fails on any growth or new shipped-source error.
Copilot AI review requested due to automatic review settings May 17, 2026 08:22
@changeset-bot

changeset-bot Bot commented May 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 40a5541

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/fixture-public-types Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator 40a5541 May 17 2026, 08:24 AM

@github-actions

Copy link
Copy Markdown
Contributor

PR template validation failed

Please fix the following issues by editing your PR description:

  • Check the "I have read CONTRIBUTING.md" checkbox.

See CONTRIBUTING.md for the full contribution policy.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n 40a5541 May 17 2026, 08:25 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 40a5541 May 17 2026, 08:25 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 40a5541 May 17 2026, 08:26 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 40a5541 May 17 2026, 08:26 AM

@pkg-pr-new

pkg-pr-new Bot commented May 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1075

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1075

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1075

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1075

emdash

npm i https://pkg.pr.new/emdash@1075

create-emdash

npm i https://pkg.pr.new/create-emdash@1075

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1075

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1075

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1075

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1075

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1075

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1075

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1075

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1075

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1075

commit: 40a5541

const baseDir = resolve(coreDir, dirname(target).replace(WILDCARD_SUFFIX, ""));
for (const abs of globSync("**/*.{ts,tsx}", { cwd: baseDir })) {
const rel = abs.replaceAll("\\", "/");
specifiers.push(toSpecifier(key.replace("*", rel)));

// #1053 sentinel: independent of the baseline file.
if (counts[SENTINEL_KEY]) {
fail(`issue #1053 regressed -- ${SENTINEL_KEY.replace("\t", " ")} reappeared in shipped source.`);
.filter(([key, n]) => n > (baseline[key] ?? 0))
.map(
([key, n]) =>
`${key.replace("\t", " ")} (now ${String(n)}, baseline ${String(baseline[key] ?? 0)})`,

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a strict-consumer TypeScript error in the WordPress-plugin import source and adds a new CI harness to typecheck all source-exported emdash/* subpaths (which ship raw .ts/.tsx and are not covered by skipLibCheck) under a Workers-typed, strict tsc configuration.

Changes:

  • Narrow the response.json() error body in wordpress-plugin.ts from unknown before reading .message (fixes TS18046 in strict consumer builds).
  • Add scripts/typecheck-public-source.mjs + a committed baseline to snapshot/guard shipped-source diagnostics per (file, TS code).
  • Add a fixtures/public-types/ consumer fixture and wire the harness into CI.

Reviewed changes

Copilot reviewed 8 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/typecheck-public-source.mjs New harness that enumerates source-exported subpaths, runs strict tsc, filters boundaries, and compares diagnostic counts to a baseline.
scripts/typecheck-public-source.baseline.json Baseline snapshot of existing (file, errorCode) diagnostic groups to prevent regressions.
packages/core/src/import/sources/wordpress-plugin.ts Fix: narrow unknown JSON error body before accessing .message.
fixtures/public-types/package.json New strict-consumer fixture package with Workers types + TypeScript.
fixtures/public-types/tsconfig.json Strict tsc config used by the harness to emulate consumer typechecking.
fixtures/public-types/env.d.ts References emdash/locals to mirror real consumer globals.
fixtures/public-types/shims.d.ts Minimal type stubs needed for the hermetic fixture (currently astro:assets).
fixtures/public-types/.gitignore Ignores generated entrypoint file used by the harness.
.github/workflows/ci.yml Adds the public-source typecheck harness to the CI typecheck job.
pnpm-lock.yaml Adds the new fixture workspace importer dependencies to the lockfile.
.changeset/wordpress-plugin-error-narrowing.md Changeset documenting the consumer-facing typecheck fix.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"compilerOptions": {
"types": ["@cloudflare/workers-types"],
"noUncheckedSideEffectImports": true,
"noEmit": true
Comment on lines +187 to +197
);
}

const parsed = parseDiagnostics(output);
if (rawErrorCount > 0 && parsed.length === 0) {
fail(
`tsc reported ${rawErrorCount} error line(s) but the parser matched none -- ` +
`diagnostic format drifted; the guard would silently pass. Fix DIAGNOSTIC_LINE.`,
);
}

@ascorbic

Copy link
Copy Markdown
Member Author

Superseded by #1076, which resolves #1053 as one coherent change: the wordpress-plugin narrowing fix plus compiling the source-exported subpaths to dist (the structural root-cause fix). The fixture-based consumer-typecheck harness here was exploratory scaffolding the final architecture makes unnecessary — #1076 replaces it with a fast static guard. Closing in favour of #1076.

@ascorbic ascorbic closed this May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type errors in emdash 0.12.0 under strict TypeScript

3 participants