diff --git a/.changeset/move-onto-temporal-polyfill.md b/.changeset/move-onto-temporal-polyfill.md new file mode 100644 index 000000000..5f0b06181 --- /dev/null +++ b/.changeset/move-onto-temporal-polyfill.md @@ -0,0 +1,59 @@ +--- +"@northguild/gmt": minor +--- + +GMT runs on `temporal-polyfill` in place of `@js-temporal/polyfill`. Every import is smaller, month arithmetic takes bounded time for any amount, and `Temporal`, `Intl` and `toTemporalInstant` are re-exported from `temporal-polyfill`. Two results and some type names change, and **Breaking changes** covers each. + +| Measured with esbuild, minified ES modules | `@js-temporal/polyfill` 0.5.1 | `temporal-polyfill` 1.0.9 | +| --- | --- | --- | +| The polyfill alone, the floor of every import | 152.5 kB minified, 44.2 kB gzipped | 65.4 kB minified, 23.3 kB gzipped | +| The whole package (`import * from "@northguild/gmt"`) | 567.8 kB minified, 154.9 kB gzipped | 528.2 kB minified, 151.9 kB gzipped | + +### Breaking changes + +**1. `compareDurations` returns `0` for two durations with the same fields, even when adding them to `relativeTo` would go past Temporal's date range.** Temporal's `Duration.compare` answers `0` for these before any arithmetic. 1.21 returned `null` when `relativeTo` was in a calendar other than ISO 8601. Equal durations that stay in range gave `0` before and still do: + +```typescript +import { compareDurations } from "@northguild/gmt"; + +compareDurations("P4294967295M", "P4294967295M", { relativeTo: "2024-01-15[u-ca=hebrew]" }); // 1.21: null. Now: 0 +compareDurations("P1Y", "P1Y"); // 0 in both +``` + +Code that treated `null` from such a call as "equal" now checks for `0`: + +```typescript +const same = compareDurations(a, b, { relativeTo }) === 0; +``` + +**2. `smallestUnit` no longer accepts `"minute"` or `"minutes"` at the type level** in `parseDuration`, and neither does `toStringSmallestUnit` in `DurationStringOptions`. The Temporal specification's `Duration#toString` takes `"second"` and smaller only. What these do at run time is unchanged, so only the type check fails: + +```typescript +import { parseDuration } from "@northguild/gmt"; + +parseDuration("PT1M30.5S", { smallestUnit: "minute" }); // now a type error +parseDuration("PT1M30.5S", { smallestUnit: "second", roundingMode: "trunc" }); // "PT1M30S" +``` + +**3. Some `Temporal.*` type names change.** `Temporal` is re-exported from `temporal-polyfill`, whose types follow `temporal-spec`. GMT's own types (`DateTimeDurationUnit`, `RoundingOptions`, `Overflow`, `Disambiguation`, `Offset`, `NowUnit`, `UtcNowUnit` and the rest) keep their names and accept the same values. Code that names a `Temporal.*` type through `@northguild/gmt` changes as follows: + +| 1.21 name | Now | +| --- | --- | +| `Temporal.DurationLike` (the fields object) | `Temporal.DurationLikeObject`. `Temporal.DurationLike` still exists but means `Duration \| DurationLikeObject \| string`, so `keyof Temporal.DurationLike` is no longer the unit names. | +| `Temporal.PlainDateLike`, `Temporal.PlainDateTimeLike`, `Temporal.PlainTimeLike`, `Temporal.ZonedDateTimeLike` (the fields objects) | `Temporal.DateLikeObject`, `Temporal.DateTimeLikeObject`, `Temporal.TimeLikeObject`, `Temporal.ZonedDateTimeLikeObject`. The old names still exist but now also take a Temporal object or a string. | +| `Temporal.SmallestUnit`, `Temporal.LargestUnit`, `Temporal.TotalUnit` | `Temporal.PluralizeUnit` (add `"auto"` for a largest unit) | +| `Temporal.PluralUnit` | `Exclude, U>` | +| `Temporal.DateTimeUnit` | `Temporal.DateUnit \| Temporal.TimeUnit` | +| `Temporal.RoundingMode` | `NonNullable["roundingMode"]>` | +| `Temporal.ArithmeticOptions`, `Temporal.ToInstantOptions`, `Temporal.ZonedDateTimeAssignmentOptions` | `Temporal.OverflowOptions`, `Temporal.DisambiguationOptions`, `Temporal.ZonedDateTimeFromOptions` | +| `Temporal.DifferenceOptions`, `Temporal.RoundTo`, `Temporal.DurationRoundTo`, `Temporal.DurationTotalOf` | `Temporal.RoundingOptionsWithLargestUnit`, `Temporal.RoundingOptions`, `Temporal.DurationRoundingOptions`, `Temporal.DurationTotalOptions` | +| `Temporal.ToStringPrecisionOptions` | `Temporal.DurationToStringOptions` (a duration) or `Temporal.ToStringRoundingOptionsWithFractionalSeconds` | +| `Temporal.ComparisonResult` | `-1 \| 0 \| 1` | + +The parameter types of these functions are printed with the new names. Each accepts the same values as before: + +- `durationFromUnits`, `ttlFromNow`, `totalUnitsFromNow`, `formatHttpDateFromNow`, and the `add*`, `subtract*`, `get*Ago` and `get*In` functions of `datetime/`, `unix/`, `utc/` and `zoned/`: `Record`. +- `getDurationUnit`, `totalDuration`, `getLargestDateTimeDurationUnit`, `isValidDateTimeDurationUnit`, and the `diff*` and `diff*AsDuration` functions of `datetime/`, `unix/`, `utc/` and `zoned/`: `keyof Temporal.DurationLikeObject`. +- `setDate`, `setDateTime`, `setTime`, `setUnix`, `setUtc` and `setZoned`: the fields they take, every one optional, era fields left out as before. +- `parseDuration`: `roundingMode` lists the nine rounding modes. +- `convertPlainDateTimeToZoned` and `getZonedNow`: `smallestUnit` is `"minute"` through `"nanosecond"`, singular or plural. diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index c6e6d374f..dae0b0928 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -1,7 +1,7 @@ { // `vitest bench` runs these; no plugin finds them. The browser twins and the worker are served // by name from vitest.browser.config.ts and loaded by URL, which no import graph shows. The - // native vitest configs load nativeTemporal.ts through an alias of `@js-temporal/polyfill`, and + // native vitest configs load nativeTemporal.ts through an alias of `temporal-polyfill/full/implementation`, and // vitest loads the native-suite reporter by path. "entry": [ "packages/gmt/src/test/nativeTemporal.ts", @@ -19,6 +19,9 @@ "@tanstack/intent", "@northguild/gmt-oxlint", "@vitest/browser-playwright", + // The last published GMT release, bundled by scripts/bundle-size.mjs for the old figures; only + // esbuild input strings name it. + "gmt-js-temporal-release", ], // The behaviour-matrix runner has its own package.json and lockfile outside the workspace. "ignorePatterns": [ diff --git a/.github/workflows/temporal-oracle.yml b/.github/workflows/temporal-oracle.yml index defa4ba21..ed14b2c38 100644 --- a/.github/workflows/temporal-oracle.yml +++ b/.github/workflows/temporal-oracle.yml @@ -6,7 +6,7 @@ name: Temporal oracle # Pulse check: polyfill-swap # # Compares GMT's calendar results against Chromium's native Temporal (test262 is the final -# authority where they disagree) and reports which @js-temporal/polyfill workarounds are still +# authority where they disagree) and reports which temporal-polyfill workarounds are still # needed. Manual and scheduled only: never part of ci.yml, because "upstream still broken" must # never fail a build. A failing oracle job means a GMT result differs from native Temporal on a # row that the script's tag list does not explain — a GMT bug to fix. @@ -27,12 +27,13 @@ name: Temporal oracle # writes a temporal-compat- verdict, so a workaround is called removable only when every # engine in its scope agrees. # -# The polyfill-swap job (CORE-92) runs the same suite on the newest `temporal-polyfill` release, -# through `temporal-polyfill/full/implementation`, beside a control pass on -# `@js-temporal/polyfill` in the same runtime. The Node leg also compares every zone's offset with +# The polyfill-swap job is the upgrade check. It runs the same suite on the newest +# `temporal-polyfill` release (the candidate, installed as `temporal-polyfill-candidate`), beside a +# control pass on the pinned version in the same runtime. When the newest release is not newer +# than the pin, the legs are skipped. The Node leg also compares every zone's offset with # `Intl.DateTimeFormat`, once a day from 1970 to ten years ahead, and every calendar's years from # ISO -3000 to 5000 with Node's built-in Temporal (CORE-110). When every leg passes and no zone or -# calendar differs, the report job opens one issue saying the swap is due. A failing swap leg never +# calendar differs, the report job opens one issue saying the upgrade is ready. A failing leg never # fails the workflow. on: @@ -54,12 +55,12 @@ on: required: false default: false swap_version: - description: "Run the swap check on this exact temporal-polyfill version (e.g. 1.0.7) instead of the latest" + description: "Run the upgrade check on this exact temporal-polyfill version (e.g. 1.0.9) instead of the newest release" type: string required: false default: "" force_swap_ready: - description: "Dry run: file a [dry run] issue as if the temporal-polyfill swap were ready" + description: "Dry run: file a [dry run] issue as if the temporal-polyfill upgrade were ready" type: boolean required: false default: false @@ -235,7 +236,8 @@ jobs: retention-days: 14 if-no-files-found: ignore - # Picks the temporal-polyfill version once, so the four swap legs test the same release. + # Picks the candidate version once, so the four legs test the same release. `skip` is true when + # the newest release is not newer than the pin, so the legs have nothing to check. swap-version: name: Temporal polyfill version runs-on: ubuntu-latest @@ -243,30 +245,30 @@ jobs: continue-on-error: true outputs: version: ${{ steps.pick.outputs.version }} + skip: ${{ steps.pick.outputs.skip }} steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-node@v7 + with: + node-version: 26 + check-latest: true + - name: Pick version id: pick env: REQUESTED: ${{ inputs.swap_version }} - run: | - version="$REQUESTED" - if [ -z "$version" ]; then - version="$(npm view temporal-polyfill version)" - fi - if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then - echo "not a x.y.z version: ${version}" >&2 - exit 1 - fi - echo "version=${version}" >> "$GITHUB_OUTPUT" + run: node scripts/swap-version.mjs # A failing leg never fails the workflow (continue-on-error): the verdict artifact and the - # report job's issues are the signals. temporal-polyfill is added inside this job's checkout - # only; nothing commits the changed package.json or lockfile. + # report job's issues are the signals. The candidate is added inside this job's checkout under + # the name `temporal-polyfill-candidate`; nothing commits the changed package.json or lockfile. polyfill-swap: name: Temporal polyfill swap (${{ matrix.leg }}) needs: swap-version # A failed swap-version (continue-on-error) still counts as success, with an empty output. - if: ${{ needs.swap-version.outputs.version != '' }} + # It also skips when the newest release is not newer than the pin. + if: ${{ needs.swap-version.outputs.version != '' && needs.swap-version.outputs.skip != 'true' }} runs-on: ubuntu-latest timeout-minutes: 45 continue-on-error: true @@ -288,13 +290,13 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile --no-runtime - - name: Install temporal-polyfill + - name: Install the candidate temporal-polyfill env: VERSION: ${{ needs.swap-version.outputs.version }} run: | # `pnpm add` has no --no-runtime and downloads the devEngines Node, so the manifest # is edited and `pnpm install --no-runtime` links the package. - npm pkg set --prefix packages/gmt "devDependencies.temporal-polyfill=${VERSION}" + npm pkg set --prefix packages/gmt "devDependencies.temporal-polyfill-candidate=npm:temporal-polyfill@${VERSION}" pnpm install --no-runtime --no-frozen-lockfile - name: Install Playwright ${{ matrix.leg }} @@ -353,7 +355,7 @@ jobs: # (GitHub Docs, "Contexts", status check functions). report: name: Report to issues - needs: [oracle, native-suite, polyfill-swap] + needs: [oracle, native-suite, swap-version, polyfill-swap] if: ${{ !cancelled() }} runs-on: ubuntu-latest timeout-minutes: 10 @@ -433,8 +435,13 @@ jobs: FORCE_MISMATCH: ${{ inputs.force_mismatch }} FORCE_NATIVE_FAILURE: ${{ inputs.force_native_failure }} FORCE_SWAP_READY: ${{ inputs.force_swap_ready }} + # True when the newest release is not newer than the pin: the four swap legs were skipped on purpose, + # so no swap verdict is expected. A failed swap-version has no `skip`, so it stays a + # could-not-run issue. + SWAP_SKIPPED: ${{ needs.swap-version.outputs.skip }} run: | args=(temporal-oracle) + if [ "$SWAP_SKIPPED" = "true" ]; then args+=(--swap-skipped); fi if [ -n "$FORCE_REMOVABLE" ]; then args+=("--force-removable=$FORCE_REMOVABLE"); fi if [ "$FORCE_MISMATCH" = "true" ]; then args+=(--force-mismatch); fi if [ "$FORCE_NATIVE_FAILURE" = "true" ]; then args+=(--force-native-failure); fi diff --git a/AGENTS.md b/AGENTS.md index 2349f8b4f..ac72bf214 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,7 +27,7 @@ Leave finished work **unstaged**. Never stage, commit, branch, push or open a PR ## Core Rules (Quick Reference) -1. **No `Date` object.** `@js-temporal/polyfill` only, imported through `packages/gmt/src/internal/temporal.ts`. +1. **No `Date` object.** `temporal-polyfill` (`/full/implementation`) only, imported through `packages/gmt/src/internal/temporal.ts`. 2. **String-in, string-out.** Never return Temporal objects. 3. **Invalid input returns a sentinel, never throws.** Table: [API Contract](./context/coding-standards/api-contract.md#api-contract). 4. **Wrap every Temporal call in `try-catch`.** One exception: [the UTC clock readers](./context/coding-standards/api-contract.md#scoped-exception-the-utc-clock-readers). diff --git a/apps/dox/evals/baseline.json b/apps/dox/evals/baseline.json index 8ad03ecef..6cc2cbb03 100644 --- a/apps/dox/evals/baseline.json +++ b/apps/dox/evals/baseline.json @@ -11,7 +11,7 @@ "metrics": { "fit.kept": 1, "refusal.quiet": 1, - "retrieval.mrr": 0.624, + "retrieval.mrr": 0.623, "retrieval.recallAt10": 1, "retrieval.withinK": 1, "tools.offered": 1, @@ -22,7 +22,7 @@ "lookup-camel-leap-second": 5, "lookup-camel-typed-name": 1, "lookup-dst-gap": 1, - "lookup-dubai-mumbai-flight": 7, + "lookup-dubai-mumbai-flight": 8, "lookup-duty-violations": 1, "lookup-fiscal-quarter": 1, "lookup-format-date": 1, diff --git a/apps/dox/lint/oxlint-config.test.ts b/apps/dox/lint/oxlint-config.test.ts new file mode 100644 index 000000000..a117b2991 --- /dev/null +++ b/apps/dox/lint/oxlint-config.test.ts @@ -0,0 +1,35 @@ +import config from "../oxlint.config.mts"; + +// The config spreads the plugin's recommended rules, which come from its build. The Tests job does +// not build `@northguild/gmt-oxlint`, and this test reads only the import ban, so the rules are empty. +vi.mock("@northguild/gmt-oxlint", () => ({ recommendedRules: {} })); + +type Override = { files: string[]; rules?: Record }; + +const RULE = "no-restricted-imports"; +const overrides = (config.overrides ?? []) as Override[]; +const setters = overrides.filter((o) => o.rules && RULE in o.rules); + +// In oxlint, as in ESLint flat config, a later override that sets a rule replaces its options for +// the files it matches. The polyfill ban holds for every Dox file only while it is the one place +// that sets the rule. +describe("the polyfill import ban", () => { + it("is the only setting of no-restricted-imports", () => { + expect(config.rules ?? {}).not.toHaveProperty(RULE); + expect(setters).toHaveLength(1); + expect(setters[0]!.files).toEqual(["src/**", "scripts/**", "tests/**"]); + }); + + it("bans both polyfills and their subpaths", () => { + const [, options] = setters[0]!.rules![RULE] as [ + string, + { paths: { name: string }[]; patterns: { group: string[] }[] }, + ]; + expect(options.paths.map((p) => p.name)).toEqual(["@js-temporal/polyfill"]); + expect(options.patterns.flatMap((p) => p.group)).toEqual([ + "@js-temporal/polyfill/**", + "temporal-polyfill", + "temporal-polyfill/**", + ]); + }); +}); diff --git a/apps/dox/oxlint.config.mts b/apps/dox/oxlint.config.mts index b1c2bce75..f37e512d2 100644 --- a/apps/dox/oxlint.config.mts +++ b/apps/dox/oxlint.config.mts @@ -132,6 +132,33 @@ export default defineConfig({ "no-unused-vars": "warn", }, overrides: [ + // CORE-108: Dox takes `Temporal` from `@northguild/gmt`, never from a polyfill. + { + files: ["src/**", "scripts/**", "tests/**"], + rules: { + "no-restricted-imports": [ + "error", + { + paths: [ + { + name: "@js-temporal/polyfill", + message: "Import Temporal from @northguild/gmt", + }, + ], + patterns: [ + { + group: ["@js-temporal/polyfill/**"], + message: "Import Temporal from @northguild/gmt", + }, + { + group: ["temporal-polyfill", "temporal-polyfill/**"], + message: "Import Temporal from @northguild/gmt", + }, + ], + }, + ], + }, + }, // Mounts and widgets stay on the component kit. { files: ["src/lib/**/*.ts", "src/widgets/**/*.{ts,tsx}"], diff --git a/apps/dox/package.json b/apps/dox/package.json index ebeaf722f..81de80a33 100644 --- a/apps/dox/package.json +++ b/apps/dox/package.json @@ -46,7 +46,6 @@ "@astrojs/react": "6.0.6", "@astrojs/sitemap": "3.7.3", "@astrojs/starlight": "0.41.11", - "@js-temporal/polyfill": "^0.5.1", "@northguild/gmt": "workspace:*", "@radix-ui/react-use-controllable-state": "^1.2.6", "@streamdown/cjk": "^1.0.3", diff --git a/apps/dox/scripts/affected.test.ts b/apps/dox/scripts/affected.test.ts index e89fbb801..3e5cf334c 100644 --- a/apps/dox/scripts/affected.test.ts +++ b/apps/dox/scripts/affected.test.ts @@ -275,6 +275,20 @@ describe("affected: which checks a change runs", () => { "test:dox", ], }, + { + name: "the bundle-size helpers run the bundle-size checks, not every check", + changes: [{ path: "scripts/lib/bundle-size.mjs", status: "M" }], + checks: [ + "format", + "bundle-size", + "build:gmt-oxlint", + "build:gmt", + "build:dox", + "dox-dist", + "typecheck:dox", + "test:dox", + ], + }, { name: "a Windows path matches like a POSIX one", changes: ["context\\domination\\tracker.md"], diff --git a/apps/dox/scripts/canary/bundle-size.test.ts b/apps/dox/scripts/canary/bundle-size.test.ts new file mode 100644 index 000000000..3c8c6a3a7 --- /dev/null +++ b/apps/dox/scripts/canary/bundle-size.test.ts @@ -0,0 +1,219 @@ +import { execFileSync } from "node:child_process"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterAll, describe, expect, it } from "vitest"; +import { + absentPathFailures, + measureEntry, + polyfillSet, + reportShape, +} from "../../../../scripts/lib/bundle-size.mjs"; + +const measure = (minified: number, gzipped: number) => ({ + minified, + gzipped, + inputs: {}, +}); + +describe("polyfillSet", () => { + it("lists bytes only, so a set carries no bundler inputs", () => { + const set = polyfillSet({ + package: "pkg-a", + version: "1.2.3", + importPath: "pkg-a/full", + shipped: true, + gmt: "9.9.9", + from: "source", + measured: { root: measure(10, 4) }, + }); + expect(set.entries).toEqual({ root: { minified: 10, gzipped: 4 } }); + }); + + it("keeps a null entry null, for a name the release does not export", () => { + const set = polyfillSet({ + package: "pkg-b", + version: "0.1.0", + importPath: "pkg-b", + shipped: false, + gmt: "1.0.0", + from: "npm", + measured: { root: measure(10, 4), gone: null }, + }); + expect(set.entries).toEqual({ + root: { minified: 10, gzipped: 4 }, + gone: null, + }); + }); + + it("names the package, version, import line, measured GMT and origin as given", () => { + const set = polyfillSet({ + package: "pkg-c", + version: "3.0.0", + importPath: "pkg-c/sub", + shipped: false, + gmt: "4.5.6", + from: "npm", + measured: {}, + }); + expect(set).toMatchObject({ + package: "pkg-c", + version: "3.0.0", + import: "pkg-c/sub", + shipped: false, + gmt: "4.5.6", + from: "npm", + }); + }); +}); + +describe("reportShape", () => { + const meta = { + measuredAt: "2026-01-02T03:04:05Z", + node: "v0", + esbuild: "0.0.0", + commit: "abc", + dirty: false, + }; + const shipped = { + package: "new-pkg", + version: "1.0.0", + importPath: "new-pkg/impl", + gmt: "2.0.0", + from: "source", + measured: { root: measure(100, 40), fl: measure(30, 12) }, + }; + const previous = { + package: "old-pkg", + version: "0.5.0", + importPath: "old-pkg", + gmt: "1.0.0", + from: "npm", + measured: { root: measure(300, 90), fl: measure(200, 70) }, + }; + const budgets = { entries: { root: { minified: 110 } } }; + + it("keeps the top-level keys and adds the budget to each shipped entry", () => { + const report = reportShape({ + meta, + floor: "fl", + budgets, + shipped, + previous, + }); + expect(report).toMatchObject({ ...meta, floor: "fl" }); + expect(report.entries).toEqual({ + root: { minified: 100, gzipped: 40, budget: 110 }, + fl: { minified: 30, gzipped: 12, budget: null }, + }); + }); + + it("lists the shipped set first, with the same entries as the top level minus the budget", () => { + const report = reportShape({ + meta, + floor: "fl", + budgets, + shipped, + previous, + }); + expect(report.polyfills.map((p: { package: string }) => p.package)).toEqual( + ["new-pkg", "old-pkg"], + ); + expect( + report.polyfills.map((p: { shipped: boolean }) => p.shipped), + ).toEqual([true, false]); + expect(report.polyfills[0].entries).toEqual({ + root: { minified: 100, gzipped: 40 }, + fl: { minified: 30, gzipped: 12 }, + }); + }); + + it("lists the shipped set alone when no previous set is measured", () => { + const report = reportShape({ + meta, + floor: "fl", + budgets, + shipped, + previous: null, + }); + expect(report.polyfills).toHaveLength(1); + }); +}); + +describe("absentPathFailures", () => { + const budgets = { absent: { entryOne: ["a/gone.ts", "a/kept.ts", "a/dir"] } }; + const kindOf = (p: string) => + p === "/root/pkg/a/kept.ts" + ? "file" + : p === "/root/pkg/a/dir" + ? "directory" + : "missing"; + + it("says does not exist for a missing path and is not a file for a directory", () => { + expect(absentPathFailures(budgets, "/root/pkg", kindOf)).toEqual([ + "entryOne: absent path a/gone.ts does not exist", + "entryOne: absent path a/dir is not a file", + ]); + }); + + it("reports nothing when every listed path is a file, or no list is given", () => { + expect(absentPathFailures(budgets, "/root/pkg", () => "file")).toEqual([]); + expect(absentPathFailures({}, "/root/pkg", () => "missing")).toEqual([]); + }); +}); + +describe("measureEntry", () => { + const dir = mkdtempSync(path.join(tmpdir(), "bundle-size-")); + writeFileSync(path.join(dir, "lib.ts"), "export const present = 1 + 2;\n"); + afterAll(() => rmSync(dir, { recursive: true, force: true })); + const entry = (name: string) => `export { ${name} } from "./lib.ts";`; + + it("measures a name the module exports", async () => { + const m = await measureEntry(entry("present"), dir, { + missingIsNull: true, + }); + expect(m?.minified).toBeGreaterThan(0); + }); + + it("returns null for a missing name when a missing name is allowed (the previous release)", async () => { + await expect( + measureEntry(entry("notAFunction"), dir, { missingIsNull: true }), + ).resolves.toBeNull(); + }); + + it("throws for a missing name when it is not allowed (the shipped set)", async () => { + await expect( + measureEntry(entry("notAFunction"), dir, { missingIsNull: false }), + ).rejects.toThrow(/No matching export/); + }); +}); + +// The Dox build runs the script from apps/dox, where esbuild's paths are relative to apps/dox, not +// the repository root. +describe("bundle-size.mjs report", () => { + const dir = mkdtempSync(path.join(tmpdir(), "bundle-size-report-")); + afterAll(() => rmSync(dir, { recursive: true, force: true })); + const appDir = path.resolve(import.meta.dirname, "../.."); + const script = path.resolve(appDir, "../../scripts/bundle-size.mjs"); + + it.each` + from | cwd + ${"apps/dox"} | ${appDir} + ${"the root"} | ${path.resolve(appDir, "../..")} + `( + "reads the previous polyfill's version when run from $from", + ({ cwd }) => { + const out = path.join(dir, `${path.basename(cwd)}.json`); + execFileSync(process.execPath, [script, "report", "--json", out], { + cwd, + stdio: "ignore", + }); + const report = JSON.parse(readFileSync(out, "utf8")); + expect( + report.polyfills.map((p: { package: string }) => p.package), + ).toEqual(["temporal-polyfill", "@js-temporal/polyfill"]); + expect(report.polyfills[1].version).toMatch(/^\d+\.\d+\.\d+$/); + }, + 60_000, + ); +}); diff --git a/apps/dox/scripts/canary/canary-issues.test.ts b/apps/dox/scripts/canary/canary-issues.test.ts index b1edda8f2..4685e691c 100644 --- a/apps/dox/scripts/canary/canary-issues.test.ts +++ b/apps/dox/scripts/canary/canary-issues.test.ts @@ -26,9 +26,9 @@ import { const RUN = "https://github.com/northguild/gmt/actions/runs/123"; const ORACLE_CONTEXT = { workflow: "temporal-oracle", runUrl: RUN } as const; const LEAP_CONTEXT = { workflow: "leap-seconds", runUrl: RUN } as const; -const RUNTIME = { polyfill: "0.5.1", node: "v24.11.0", icu: "77.1" }; +const RUNTIME = { polyfill: "1.0.8", node: "v24.11.0", icu: "77.1" }; -type State = "still-needed" | "removable" | "guard" | "out-of-scope"; +type State = "still-needed" | "removable" | "out-of-scope"; const workaround = ( id: string, @@ -46,19 +46,12 @@ const workaround = ( ...extra, }); -const GUARD = { - package: "@js-temporal/polyfill", - through: "0.5.1", - reason: "no probe can tell a pre-fix polyfill from a fixed one", -}; - type Workaround = ReturnType; const countsOf = (workarounds: Workaround[]) => ({ workarounds: workarounds.length, stillNeeded: workarounds.filter((w) => w.state === "still-needed").length, removable: workarounds.filter((w) => w.state === "removable").length, - guard: workarounds.filter((w) => w.state === "guard").length, outOfScope: workarounds.filter((w) => w.state === "out-of-scope").length, }); @@ -97,7 +90,7 @@ const browserCompat = (leg: BrowserLeg, workarounds: Workaround[]) => ({ leg, engine: BROWSER_ENGINES[leg], engineId: BROWSER_ENGINE_IDS[leg], - runtime: { polyfill: "0.5.1", node: "v24.11.0", playwright: "1.63.0" }, + runtime: { polyfill: "1.0.8", node: "v24.11.0", playwright: "1.63.0" }, counts: countsOf(workarounds), workarounds, }); @@ -177,10 +170,7 @@ const couldNotRun = (source: string, message: string) => ({ }); const cleanCheck = () => - check([ - workaround("D1", "still-needed"), - workaround("D10", "guard", { guard: { ...GUARD, lapsed: false } }), - ]); + check([workaround("D1", "still-needed"), workaround("D17", "out-of-scope")]); const NATIVE_LEGS = [ "node", @@ -311,6 +301,7 @@ const calendarSweep = (differingCalendars = 0) => ({ interface SwapOptions { version?: string; + pinned?: string; failed?: number; both?: number; fixed?: number; @@ -330,7 +321,8 @@ const swapLeg = (leg: SwapLeg, options: SwapOptions = {}) => { status: "ran" as const, leg, version, - entry: "temporal-polyfill/full/implementation", + pinned: options.pinned ?? "1.0.6", + entry: "temporal-polyfill-candidate/full/implementation", entryLoaded: options.entryLoaded ?? true, runtime: { node: "26.12.1", @@ -481,7 +473,7 @@ describe("constants and marker", () => { }); describe("the finding plan: no-op and open", () => { - it("1: no-op when every group is still needed or guarded and the oracle is clean", () => { + it("1: no-op when every group is still needed or out of scope and the oracle is clean", () => { expect( plan({ "temporal-compat-check": cleanCheck(), @@ -512,7 +504,7 @@ describe("removable body", () => { it("states the polyfill, the engines in scope, the trigger and the scope", () => { expect(body()).toContain( - `Every probe for **D2** returns the spec value on @js-temporal/polyfill 0.5.1 on every engine in its scope (${EVERY_ENGINE}), so the workaround can go.`, + `Every probe for **D2** returns the spec value on temporal-polyfill 1.0.8 on every engine in its scope (${EVERY_ENGINE}), so the workaround can go.`, ); expect(body()).toContain("**Trigger:** trigger for D2"); expect(body()).toContain("**Scope:** every engine."); @@ -533,47 +525,6 @@ describe("removable body", () => { ); }); - it("14: a lapsed guard adds the Guard lapsed paragraph", () => { - const verdicts = { - "temporal-compat-check": check([ - workaround("D10", "removable", { - guard: { ...GUARD, lapsed: true }, - }), - ]), - "temporal-oracle": oracle(), - }; - const [action] = plan(verdicts); - if (action.kind !== "open") throw new Error("expected open"); - expect(action.body).toContain( - "**Guard lapsed:** it held through @js-temporal/polyfill 0.5.1 (no probe can tell a pre-fix polyfill from a fixed one). Before removing, confirm the installed release is the trigger; if it is not, raise guard.through to it and close this issue.", - ); - }); - - it("14c: a guard reason that ends with a period loses it inside the parentheses", () => { - const verdicts = { - "temporal-compat-check": check([ - workaround("D10", "removable", { - guard: { - ...GUARD, - reason: "no probe can tell a pre-fix polyfill from a fixed one.", - lapsed: true, - }, - }), - ]), - "temporal-oracle": oracle(), - }; - const [action] = plan(verdicts); - if (action.kind !== "open") throw new Error("expected open"); - expect(action.body).toContain( - "(no probe can tell a pre-fix polyfill from a fixed one). Before removing", - ); - expect(action.body).not.toContain(".). Before removing"); - }); - - it("14b: no Guard lapsed paragraph for a group without a guard", () => { - expect(body()).not.toContain("Guard lapsed"); - }); - it("15: a stale snapshot says the snapshot is due now", () => { const verdicts = { "temporal-compat-check": check([workaround("D2", "removable")], false), @@ -592,9 +543,9 @@ describe("removable body", () => { ); }); - it("16: the numbered steps end with the polyfill floor bump", () => { + it("16: the numbered steps end with the polyfill pin bump", () => { expect(body()).toContain( - "### Removal steps\n\n1. Delete the D2 repros\n2. Drop the D2 compat module\n3. Raise the @js-temporal/polyfill floor in packages/gmt/package.json to the release that made this removable, so no install resolves one with the defect.", + "### Removal steps\n\n1. Delete the D2 repros\n2. Drop the D2 compat module\n3. Raise the temporal-polyfill pin in packages/gmt/package.json to the release that made this removable, so no install resolves one with the defect.", ); }); @@ -706,7 +657,7 @@ describe("removable on every engine in scope", () => { if (action.kind !== "open") throw new Error("expected open"); expect(action.key).toBe("temporal-compat/removable/D17"); expect(action.body).toContain( - "Every probe for **D17** returns the spec value on @js-temporal/polyfill 0.5.1 on every engine in its scope (Firefox 155.0), so the workaround can go.", + "Every probe for **D17** returns the spec value on temporal-polyfill 1.0.8 on every engine in its scope (Firefox 155.0), so the workaround can go.", ); expect(action.body).toContain( "**Scope:** only firefox: only that engine's Intl shows the defect, so the other rows are out of scope and count for nothing.", @@ -794,8 +745,8 @@ describe("removable on every engine in scope", () => { }; const states = compatStates(verdicts as never); expect(states.map((s) => [s.id, s.polyfill, s.everywhere])).toEqual([ - ["D2", "0.5.1", false], - ["D8", "0.5.1", false], + ["D2", "1.0.8", false], + ["D8", "1.0.8", false], ]); }); }); @@ -835,7 +786,7 @@ describe("untagged mismatch", () => { "3 of 410000 comparisons differ from Chromium 152.0.7444.0's native Temporal and no entry in TAGGED_MISMATCHES explains them. Each is a GMT bug unless test262 disagrees with Chromium; then tag it with its test262 file.", ); expect(body).toContain( - "@js-temporal/polyfill 0.5.1 · Node v24.11.0 · ICU 77.1 · Chromium 152.0.7444.0", + "temporal-polyfill 1.0.8 · Node v24.11.0 · ICU 77.1 · Chromium 152.0.7444.0", ); expect(body).toContain( "### Groups\n\n| Scan, calendar, op | Rows | Example |\n| --- | --- | --- |\n| grid hebrew addMonth | 3 | `{", @@ -1098,19 +1049,17 @@ describe("applyForce and forced findings", () => { ); }); - it("17b: a forced guard group states guard as its real state", () => { + it("17b: a forced out-of-scope group states out of scope as its real state", () => { const { verdicts } = applyForce( { - "temporal-compat-check": check([ - workaround("D10", "guard", { guard: { ...GUARD, lapsed: false } }), - ]), + "temporal-compat-check": check([workaround("D17", "out-of-scope")]), "temporal-oracle": oracle(), } as never, - { removable: "D10" }, + { removable: "D17" }, ); const [action] = forcedOpen(verdicts); expect(action.body).toContain( - "Real state on this run: guard on Node v24.11.0; guard on Chromium 153.0.8010.12; guard on Firefox 155.0; guard on WebKit 26.6; guard on macOS WebKit 26.6 \u00b7 macOS 15.7.2.", + "Real state on this run: out of scope on Node v24.11.0; out of scope on Chromium 153.0.8010.12; out of scope on Firefox 155.0; out of scope on WebKit 26.6; out of scope on macOS WebKit 26.6 \u00b7 macOS 15.7.2.", ); }); @@ -1397,12 +1346,12 @@ describe("findings", () => { /** The three fixed paragraphs, written out here word for word. */ const TRIAGE = - "Each row failed on the native engine and passed on @js-temporal/polyfill in the same runtime. Decide which it is: a GMT defect (fix it), a polyfill defect or an engine or specification defect (record it in context/domination/js-temporal-polyfill-bugs.md and tag the test in scripts/lib/native-suite-tags.mjs). Never skip the test."; + "Each row failed on the native engine and passed on temporal-polyfill in the same runtime. Decide which it is: a GMT defect (fix it), a polyfill defect or an engine or specification defect (record it in context/domination/js-temporal-polyfill-bugs.md and tag the test in scripts/lib/native-suite-tags.mjs). Never skip the test."; const HOST = - "Each row failed on the native engine and on @js-temporal/polyfill in the same runtime, so the cause is the runtime (its locale or time zone data, or its setup), not Temporal. Find what the runtime lacks, then add or widen a group in KNOWN_HOST_FAILURES in scripts/lib/native-suite-tags.mjs with that reason — one group per cause, never one entry per test — or fix the test if it depends on the host by mistake. Never skip the test."; + "Each row failed on the native engine and on temporal-polyfill in the same runtime, so the cause is the runtime (its locale or time zone data, or its setup), not Temporal. Find what the runtime lacks, then add or widen a group in KNOWN_HOST_FAILURES in scripts/lib/native-suite-tags.mjs with that reason — one group per cause, never one entry per test — or fix the test if it depends on the host by mistake. Never skip the test."; const CONTROL = - "Each row failed on @js-temporal/polyfill and passed on the native engine in the same runtime. GMT ships the polyfill, so this is a wrong answer GMT gives users of that runtime. Find the polyfill defect, record it in context/domination/js-temporal-polyfill-bugs.md and fix GMT's answer with a temporalCompat workaround, or fix GMT if the defect is its own. There is no tag for these rows. Never skip the test."; + "Each row failed on temporal-polyfill and passed on the native engine in the same runtime. GMT ships the polyfill, so this is a wrong answer GMT gives users of that runtime. Find the polyfill defect, record it in context/domination/js-temporal-polyfill-bugs.md and fix GMT's answer with a temporalCompat workaround, or fix GMT if the defect is its own. There is no tag for these rows. Never skip the test."; /** The untagged-failure key of one engine: each engine gets its own issue. */ const failureKey = (leg: string) => `native-suite/untagged-failure/${leg}`; @@ -1931,10 +1880,10 @@ describe("swapReady", () => { it.each` label | verdicts | reason - ${"chromium entryLoaded is false"} | ${cleanSwap({ chromium: { entryLoaded: false } })} | ${"temporal-polyfill-swap-chromium: the swap pass did not load temporal-polyfill"} - ${"firefox entryLoaded is missing"} | ${changed("firefox", (v) => delete v.entryLoaded)} | ${"temporal-polyfill-swap-firefox: the swap pass did not load temporal-polyfill"} - ${"node entryLoaded is the string true"} | ${cleanSwap({ node: { entryLoaded: "true" } })} | ${"temporal-polyfill-swap-node: the swap pass did not load temporal-polyfill"} - ${"entry not loaded beats failing tests"} | ${cleanSwap({ webkit: { entryLoaded: false, failed: 5 } })} | ${"temporal-polyfill-swap-webkit: the swap pass did not load temporal-polyfill"} + ${"chromium entryLoaded is false"} | ${cleanSwap({ chromium: { entryLoaded: false } })} | ${"temporal-polyfill-swap-chromium: the swap pass did not load the candidate"} + ${"firefox entryLoaded is missing"} | ${changed("firefox", (v) => delete v.entryLoaded)} | ${"temporal-polyfill-swap-firefox: the swap pass did not load the candidate"} + ${"node entryLoaded is the string true"} | ${cleanSwap({ node: { entryLoaded: "true" } })} | ${"temporal-polyfill-swap-node: the swap pass did not load the candidate"} + ${"entry not loaded beats failing tests"} | ${cleanSwap({ webkit: { entryLoaded: false, failed: 5 } })} | ${"temporal-polyfill-swap-webkit: the swap pass did not load the candidate"} ${"webkit failed count is missing"} | ${changed("webkit", (v) => delete v.counts.failed)} | ${"temporal-polyfill-swap-webkit: the failed count is missing"} ${"node counts are missing"} | ${changed("node", (v) => delete v.counts)} | ${"temporal-polyfill-swap-node: the failed count is missing"} ${"chromium failed count is the string 0"} | ${changed("chromium", (v) => (v.counts.failed = "0"))} | ${"temporal-polyfill-swap-chromium: the failed count is missing"} @@ -1961,8 +1910,8 @@ describe("swapReady", () => { ${"chromium could not run"} | ${{ ...cleanSwap(), "temporal-polyfill-swap-chromium": couldNotRun("temporal-polyfill-swap-chromium", "no browser") }} | ${"temporal-polyfill-swap-chromium: did not run"} ${"webkit key absent"} | ${Object.fromEntries(Object.entries(cleanSwap()).filter(([k]) => !k.endsWith("webkit")))} | ${"temporal-polyfill-swap-webkit: did not run"} ${"versions differ"} | ${cleanSwap({ firefox: { version: "1.0.8" } })} | ${"legs ran different versions: 1.0.7, 1.0.8"} - ${"three tests fail on webkit"} | ${cleanSwap({ webkit: { failed: 3 } })} | ${"temporal-polyfill-swap-webkit: 3 tests fail on the swap"} - ${"one test fails on node"} | ${cleanSwap({ node: { failed: 1 } })} | ${"temporal-polyfill-swap-node: 1 test fails on the swap"} + ${"three tests fail on webkit"} | ${cleanSwap({ webkit: { failed: 3 } })} | ${"temporal-polyfill-swap-webkit: 3 tests fail on the candidate"} + ${"one test fails on node"} | ${cleanSwap({ node: { failed: 1 } })} | ${"temporal-polyfill-swap-node: 1 test fails on the candidate"} ${"sweep could not run"} | ${cleanSwap({ node: { sweep: { status: "could-not-run", message: "no Intl" } } })} | ${"offset sweep: did not run"} ${"sweep is null on node"} | ${cleanSwap({ node: { sweep: null } })} | ${"offset sweep: did not run"} ${"calendar sweep could not run"} | ${cleanSwap({ node: { calendarSweep: { status: "could-not-run", message: "no Temporal" } } })} | ${"calendar sweep: did not run"} @@ -1974,15 +1923,58 @@ describe("swapReady", () => { ${"one zone differs"} | ${cleanSwap({ node: { sweep: swapSweep(1) } })} | ${"offset sweep: 1 zone differs"} ${"a missing leg beats a failing one"} | ${{ ...cleanSwap({ node: { failed: 4 } }), "temporal-polyfill-swap-webkit": null }} | ${"temporal-polyfill-swap-webkit: did not run"} ${"versions beat failures"} | ${cleanSwap({ node: { failed: 4 }, webkit: { version: "1.0.9" } })} | ${"legs ran different versions: 1.0.7, 1.0.9"} - ${"failures beat the sweep"} | ${cleanSwap({ chromium: { failed: 2 }, node: { sweep: swapSweep(5) } })} | ${"temporal-polyfill-swap-chromium: 2 tests fail on the swap"} + ${"failures beat the sweep"} | ${cleanSwap({ chromium: { failed: 2 }, node: { sweep: swapSweep(5) } })} | ${"temporal-polyfill-swap-chromium: 2 tests fail on the candidate"} `("is not ready when $label", ({ verdicts, reason }) => { expect(swapReady(verdicts)).toEqual({ ready: false, reason }); }); }); +describe("swap legs skipped on purpose", () => { + const SKIPPED = { ...ORACLE_CONTEXT, swapSkipped: true }; + const withoutSwap = (verdicts: unknown) => + Object.fromEntries( + Object.entries(withNative(verdicts) as Record).filter( + ([source]) => !SWAP_SOURCES.includes(source), + ), + ) as never; + const base = { + "temporal-compat-check": cleanCheck(), + "temporal-oracle": oracle(), + }; + + it("no swap verdicts and the swap-skipped flag file no could-not-run issue", () => { + expect( + planIssueActions(withoutSwap(base), [], SKIPPED).map((a) => a.key), + ).toEqual([]); + }); + + it("no swap verdicts without the flag is a could-not-run issue naming the four swap sources", () => { + const actions = planIssueActions(withoutSwap(base), [], ORACLE_CONTEXT); + expect(actions).toHaveLength(1); + const [action] = actions; + if (action.kind !== "open") throw new Error("expected open"); + expect(action.findings).toEqual(["temporal-oracle/could-not-run"]); + for (const source of SWAP_SOURCES) expect(action.body).toContain(source); + }); + + it("an empty verdict set with the flag still reports the other sources as could-not-run", () => { + const keys = findings({}, SKIPPED).map((f) => f.key); + expect(keys).toEqual(["temporal-oracle/could-not-run"]); + const [finding] = findings({}, SKIPPED); + expect(finding.body).toContain("temporal-oracle"); + expect(finding.body).not.toContain("temporal-polyfill-swap"); + }); + + it("an empty verdict set without the flag lists the swap sources too", () => { + expect(findings({}, ORACLE_CONTEXT)[0].body).toContain( + "temporal-polyfill-swap-node", + ); + }); +}); + describe("swap findings", () => { const READY_TITLE = - "Swap to temporal-polyfill 1.0.7: it passes the GMT suite and both sweeps"; + "temporal-polyfill 1.0.7 passes on every runtime against the pinned 1.0.6: raise the pin"; const READY_MARKER = ''; const swapPlan = (swap: unknown, open: ReturnType[] = []) => plan( @@ -2005,6 +1997,47 @@ describe("swap findings", () => { expect(action.body.split("\n")[0]).toBe(READY_MARKER); }); + it("a candidate equal to the pin says the self-test passed and there is nothing to change", () => { + const [action] = swapPlan( + cleanSwap({ + node: { pinned: "1.0.7" }, + chromium: { pinned: "1.0.7" }, + firefox: { pinned: "1.0.7" }, + webkit: { pinned: "1.0.7" }, + }), + ); + if (action.kind !== "open") throw new Error("expected open"); + expect(action.title).toBe( + "temporal-polyfill 1.0.7 self-test passed: the pin is already 1.0.7, nothing to change", + ); + expect(action.body).toContain( + "The pin in `packages/gmt/package.json` is already 1.0.7, so there is nothing to change.", + ); + expect(action.body).not.toContain("raise the pin"); + expect(action.body).not.toContain("To raise the pin"); + expect(action.body).not.toContain("pnpm install"); + }); + + it("a candidate older than the pin says there is nothing to change, never to raise the pin", () => { + const [action] = swapPlan( + cleanSwap({ + node: { pinned: "1.0.8" }, + chromium: { pinned: "1.0.8" }, + firefox: { pinned: "1.0.8" }, + webkit: { pinned: "1.0.8" }, + }), + ); + if (action.kind !== "open") throw new Error("expected open"); + expect(action.title).toBe( + "temporal-polyfill 1.0.7 passes on every runtime, but it is older than the pinned 1.0.8: nothing to change", + ); + expect(action.body).toContain( + "1.0.7 is older than the pin in `packages/gmt/package.json`, 1.0.8, so there is nothing to change.", + ); + expect(action.body).not.toContain("raise the pin"); + expect(action.body).not.toContain("pnpm install"); + }); + it("a run that ran but is not swap-ready files nothing", () => { expect(swapPlan(cleanSwap({ webkit: { failed: 2 } }))).toEqual([]); }); @@ -2037,9 +2070,9 @@ describe("swap findings", () => { expect(action.body).toBe( [ READY_MARKER, - `temporal-polyfill 1.0.7, imported from \`temporal-polyfill/full/implementation\`, passed every check on this run.`, + `temporal-polyfill 1.0.7 passes the GMT suite on every runtime against the pinned 1.0.6, and it passed every check on this run.`, "", - "| Runtime | Tests | Fail on swap only | Fail on both | Fail only on @js-temporal/polyfill |", + "| Runtime | Tests | Fail on 1.0.7 only | Fail on both | Fail on 1.0.6 only |", "| --- | --- | --- | --- | --- |", "| Node 26.12.1 | 71337 | 0 | 0 | 0 |", "| Chromium 153.0.8010.12 | 71337 | 0 | 9 | 0 |", @@ -2050,9 +2083,15 @@ describe("swap findings", () => { "", "Calendar sweep: every one of 16 calendars matches the built-in Temporal on the first day, months and days of each year from -003000-01-01 to +005000-12-31.", "", - "What the swap involves is in [temporal-polyfill-swap.md § 5 and § 7](https://github.com/northguild/gmt/blob/main/context/domination/research/temporal-polyfill-swap.md). Type errors are not checked here; § 5 lists them.", + "To raise the pin:", + "", + '1. Set `dependencies["temporal-polyfill"]` in `packages/gmt/package.json` to `1.0.7`, then run `pnpm install`.', + "2. Run `pnpm compat`, then remove each workaround it reports as removable, following the steps it prints.", + "3. Run `pnpm size`, then change the bundle budgets only by a reviewed edit.", + "", + "Type errors are not checked here: run `pnpm typecheck` after step 1. The history of this check is in [temporal-polyfill-swap.md § 5 and § 7](https://github.com/northguild/gmt/blob/main/context/domination/research/temporal-polyfill-swap.md).", "", - "A person makes the swap. CI opens issues, never pull requests.", + "A person raises the pin. CI opens issues, never pull requests.", "", `Run: ${RUN}`, ].join("\n"), @@ -2271,14 +2310,14 @@ describe("swap force", () => { const dry = actions[1]; if (dry.kind !== "open") throw new Error("expected open"); expect(dry.title).toBe( - "[dry run] Swap to temporal-polyfill 1.0.7: it passes the GMT suite and both sweeps", + "[dry run] temporal-polyfill 1.0.7 passes on every runtime against the pinned 1.0.6: raise the pin", ); expect(dry.labels).toEqual(["canary", "canary-dry-run"]); expect(dry.body).toContain( "Forced for a dry run. Real result on this run: every check passed.", ); expect(dry.body).toContain( - `temporal-polyfill 1.0.7, imported from \`temporal-polyfill/full/implementation\`, passed every check on this run.`, + "temporal-polyfill 1.0.7 passes the GMT suite on every runtime against the pinned 1.0.6, and it passed every check on this run.", ); }); @@ -2288,10 +2327,10 @@ describe("swap force", () => { const [dry] = actions; if (dry.kind !== "open") throw new Error("expected open"); expect(dry.body).toContain( - "Forced for a dry run. Real result on this run: not ready to swap. The first check that blocks it: temporal-polyfill-swap-webkit: 2 tests fail on the swap.", + "Forced for a dry run. Real result on this run: not ready to swap. The first check that blocks it: temporal-polyfill-swap-webkit: 2 tests fail on the candidate.", ); expect(dry.body).toContain( - `temporal-polyfill 1.0.7, imported from \`temporal-polyfill/full/implementation\`, was checked on this run.`, + "temporal-polyfill 1.0.7 was checked against the pinned 1.0.6 on this run.", ); expect(dry.body).not.toContain("passed every check"); expect(dry.body).toContain("| WebKit 26.6 | 71337 | 2 | 0 | 0 |"); diff --git a/apps/dox/scripts/canary/canary-report.test.ts b/apps/dox/scripts/canary/canary-report.test.ts index f598bfd7f..9b845f129 100644 --- a/apps/dox/scripts/canary/canary-report.test.ts +++ b/apps/dox/scripts/canary/canary-report.test.ts @@ -406,6 +406,17 @@ describe("parseArgs", () => { }); }); + it("reads --swap-skipped for the oracle workflow only", () => { + expect(parseArgs(["temporal-oracle", "--swap-skipped"])).toEqual({ + ok: true, + workflow: "temporal-oracle", + force: {}, + print: false, + swapSkipped: true, + }); + expect(parseArgs(["leap-seconds", "--swap-skipped"]).ok).toBe(false); + }); + it("reads the swap flag for the oracle workflow", () => { expect( parseArgs(["temporal-oracle", "--force-swap-ready", "--print"]), @@ -800,6 +811,31 @@ describe("main", () => { ]); }); + it("--swap-skipped with no swap files files no could-not-run issue", () => { + writeOracleFiles(); + for (const leg of ["node", "chromium", "firefox", "webkit"]) { + rmSync(join(root, "artifacts", `temporal-polyfill-swap-${leg}.json`)); + } + const { code, out } = run(["temporal-oracle", "--swap-skipped", "--print"]); + expect(code).toBe(0); + expect(out).toContain( + "Skipped: the pinned temporal-polyfill is the newest release", + ); + expect(out).not.toContain("Not ready"); + expect(out.trimEnd().endsWith("[]")).toBe(true); + }); + + it("no swap files without --swap-skipped is a could-not-run issue", () => { + writeOracleFiles(); + for (const leg of ["node", "chromium", "firefox", "webkit"]) { + rmSync(join(root, "artifacts", `temporal-polyfill-swap-${leg}.json`)); + } + const { out } = run(["temporal-oracle", "--print"]); + const actions = JSON.parse(out.slice(out.indexOf("[\n"))); + expect(actions).toHaveLength(1); + expect(actions[0].findings).toEqual(["temporal-oracle/could-not-run"]); + }); + it("an unreadable swap verdict reads as could-not-run and is listed in the could-not-run issue", () => { writeOracleFiles(); writeReadySwapFiles(); diff --git a/apps/dox/scripts/canary/canary-summary.test.ts b/apps/dox/scripts/canary/canary-summary.test.ts index 559082ca9..e632df5ee 100644 --- a/apps/dox/scripts/canary/canary-summary.test.ts +++ b/apps/dox/scripts/canary/canary-summary.test.ts @@ -5,22 +5,16 @@ import { summaryMarkdown } from "../../../../scripts/lib/canary-summary.mjs"; * module. Fixtures are hand-written verdicts in the verdict-file schemas. */ -const RUNTIME = { polyfill: "0.5.1", node: "v24.11.0", icu: "77.1" }; +const RUNTIME = { polyfill: "1.0.8", node: "v24.11.0", icu: "77.1" }; -const guardWorkaround = { - id: "D10", - defects: ["D10"], - title: "D10 — fields to ISO skip a month", +const stillNeededWorkaround = { + id: "D16", + defects: ["D16"], + title: "D16 — range drops zone-name widths", trigger: "trigger", - state: "guard", + state: "still-needed", probes: 2, - failing: 0, - guard: { - package: "@js-temporal/polyfill", - through: "0.5.1", - reason: "no probe can tell", - lapsed: false, - }, + failing: 1, steps: ["step"], }; @@ -50,7 +44,7 @@ const check = ( }); const cleanCheck = () => - check([guardWorkaround], { stillNeeded: 15, removable: 0, guard: 1 }); + check([stillNeededWorkaround], { stillNeeded: 15, removable: 0 }); const BROWSER_ENGINE_IDS: Record = { chromium: "v8", @@ -70,7 +64,7 @@ const compat = ( leg, engine: ENGINES[leg], engineId: BROWSER_ENGINE_IDS[leg], - runtime: { polyfill: "0.5.1", node: "v26.10.0", playwright: "1.63.0" }, + runtime: { polyfill: "1.0.8", node: "v26.10.0", playwright: "1.63.0" }, counts: { workarounds: 16, outOfScope: 0, ...counts }, workarounds, }); @@ -79,10 +73,9 @@ const cleanCompat = () => Object.fromEntries( ["chromium", "firefox", "webkit", "webkit-macos"].map((leg) => [ `temporal-compat-${leg}`, - compat(leg, [guardWorkaround], { + compat(leg, [stillNeededWorkaround], { stillNeeded: 15, removable: 0, - guard: 1, }), ]), ); @@ -215,7 +208,8 @@ const swap = (leg: string, over: Record = {}) => ({ status: "ran", leg, version: "1.0.7", - entry: "temporal-polyfill/full/implementation", + pinned: "1.0.6", + entry: "temporal-polyfill-candidate/full/implementation", entryLoaded: true, runtime: { node: "26.12.1", @@ -255,11 +249,11 @@ const clean = () => ({ }); const SWAP_BLOCK = [ - "### Temporal polyfill swap", + "### Temporal polyfill upgrade check", "", - "temporal-polyfill 1.0.7 — Ready to swap", + "temporal-polyfill 1.0.7 — Ready to raise the pin", "", - "| Runtime | Tests | Fail on swap only | Fail on both |", + "| Runtime | Tests | Fail on candidate only | Fail on both |", "| --- | --- | --- | --- |", "| node | 71337 | 0 | 0 |", "| chromium | 71337 | 0 | 0 |", @@ -274,21 +268,20 @@ const SWAP_BLOCK = [ const CLEAN_SUMMARY = [ "## Temporal oracle", "", - "@js-temporal/polyfill 0.5.1 · Node v24.11.0 · ICU 77.1 · Chromium 152.0.7444.0", + "temporal-polyfill 1.0.8 · Node v24.11.0 · ICU 77.1 · Chromium 152.0.7444.0", "", "| Workarounds | Count |", "| --- | --- |", "| Still needed | 15 |", "| Removable | 0 |", - "| Guard | 1 (D10, through @js-temporal/polyfill 0.5.1) |", "", - "| Compat source | Engine | Still needed | Removable | Guard | Out of scope |", - "| --- | --- | --- | --- | --- | --- |", - "| temporal-compat-check | Node v24.11.0 (v8) | 15 | 0 | 1 | 0 |", - "| temporal-compat-chromium | Chromium 153.0.8010.12 (v8) | 15 | 0 | 1 | 0 |", - "| temporal-compat-firefox | Firefox 155.0 (firefox) | 15 | 0 | 1 | 0 |", - "| temporal-compat-webkit | WebKit 26.6 (webkit) | 15 | 0 | 1 | 0 |", - "| temporal-compat-webkit-macos | macOS WebKit 26.6 \u00b7 macOS 15.7.2 (webkit) | 15 | 0 | 1 | 0 |", + "| Compat source | Engine | Still needed | Removable | Out of scope |", + "| --- | --- | --- | --- | --- |", + "| temporal-compat-check | Node v24.11.0 (v8) | 15 | 0 | 0 |", + "| temporal-compat-chromium | Chromium 153.0.8010.12 (v8) | 15 | 0 | 0 |", + "| temporal-compat-firefox | Firefox 155.0 (firefox) | 15 | 0 | 0 |", + "| temporal-compat-webkit | WebKit 26.6 (webkit) | 15 | 0 | 0 |", + "| temporal-compat-webkit-macos | macOS WebKit 26.6 \u00b7 macOS 15.7.2 (webkit) | 15 | 0 | 0 |", "", "| Oracle | Count |", "| --- | --- |", @@ -316,7 +309,7 @@ const CLEAN_SUMMARY = [ ].join("\n"); describe("summaryMarkdown: temporal-oracle", () => { - it("clean oracle run with D10 guard: the whole layout", () => { + it("clean oracle run: the whole layout", () => { expect(oracleSummary(clean())).toBe(CLEAN_SUMMARY); }); @@ -429,11 +422,11 @@ describe("summaryMarkdown: temporal-oracle", () => { ...compatEverywhere( [ removableWorkaround("D2"), - guardWorkaround, + stillNeededWorkaround, { ...removableWorkaround("D5"), state: "still-needed", failing: 2 }, removableWorkaround("D8"), ], - { stillNeeded: 13, removable: 2, guard: 1 }, + { stillNeeded: 13, removable: 2 }, ), "temporal-oracle": oracle(), }; @@ -445,7 +438,7 @@ describe("summaryMarkdown: temporal-oracle", () => { expect(text).toContain("| Removable | 2 |"); expect(text).toContain("| Still needed | 13 |"); expect(text).toContain( - "| temporal-compat-webkit | WebKit 26.6 (webkit) | 13 | 2 | 1 | 0 |", + "| temporal-compat-webkit | WebKit 26.6 (webkit) | 13 | 2 | 0 |", ); }); @@ -454,12 +447,11 @@ describe("summaryMarkdown: temporal-oracle", () => { "temporal-compat-check": check([removableWorkaround("D2")], { stillNeeded: 15, removable: 1, - guard: 0, }), "temporal-compat-chromium": compat( "chromium", [{ ...removableWorkaround("D2"), state: "still-needed", failing: 2 }], - { stillNeeded: 16, removable: 0, guard: 0 }, + { stillNeeded: 16, removable: 0 }, ), "temporal-compat-firefox": { source: "temporal-compat-firefox", @@ -474,13 +466,13 @@ describe("summaryMarkdown: temporal-oracle", () => { "Removable on some engines only: D2 (Node v24.11.0: removable; Chromium 153.0.8010.12: still needed, 2 of 2 probes fail; temporal-compat-firefox: no verdict; temporal-compat-webkit: no verdict; temporal-compat-webkit-macos: no verdict)", ); expect(lines).toContain( - "| temporal-compat-firefox | could not run — the compat page failed in firefox: boom | — | — | — | — |", + "| temporal-compat-firefox | could not run — the compat page failed in firefox: boom | — | — | — |", ); expect(lines).toContain( - "| temporal-compat-webkit | could not run — no verdict file: an earlier step or job failed | — | — | — | — |", + "| temporal-compat-webkit | could not run — no verdict file: an earlier step or job failed | — | — | — |", ); expect(lines).toContain( - "| temporal-compat-webkit-macos | could not run — no verdict file: an earlier step or job failed | — | — | — | — |", + "| temporal-compat-webkit-macos | could not run — no verdict file: an earlier step or job failed | — | — | — |", ); }); @@ -491,30 +483,25 @@ describe("summaryMarkdown: temporal-oracle", () => { "temporal-compat-check": check([elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-compat-chromium": compat("chromium", [elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-compat-firefox": compat("firefox", [d17], { stillNeeded: 15, removable: 1, - guard: 0, }), "temporal-compat-webkit": compat("webkit", [elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-compat-webkit-macos": compat("webkit-macos", [elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-oracle": oracle(), @@ -522,10 +509,10 @@ describe("summaryMarkdown: temporal-oracle", () => { const lines = oracleSummary(verdicts).split("\n"); expect(lines).toContain("Removable on every engine in scope: D17"); expect(lines).toContain( - "| temporal-compat-check | Node v24.11.0 (v8) | 15 | 0 | 0 | 1 |", + "| temporal-compat-check | Node v24.11.0 (v8) | 15 | 0 | 1 |", ); expect(lines).toContain( - "| temporal-compat-firefox | Firefox 155.0 (firefox) | 15 | 1 | 0 | 0 |", + "| temporal-compat-firefox | Firefox 155.0 (firefox) | 15 | 1 | 0 |", ); }); @@ -537,29 +524,24 @@ describe("summaryMarkdown: temporal-oracle", () => { "temporal-compat-check": check([elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-compat-chromium": compat("chromium", [elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-compat-firefox": compat("firefox", [d17], { stillNeeded: 15, removable: 1, - guard: 0, }), "temporal-compat-webkit": compat("webkit", [failing], { stillNeeded: 16, removable: 0, - guard: 0, }), "temporal-compat-webkit-macos": compat("webkit-macos", [elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-oracle": oracle(), @@ -578,7 +560,6 @@ describe("summaryMarkdown: temporal-oracle", () => { "temporal-compat-check": check([elsewhere], { stillNeeded: 15, removable: 0, - guard: 0, outOfScope: 1, }), "temporal-oracle": oracle(), @@ -586,46 +567,11 @@ describe("summaryMarkdown: temporal-oracle", () => { expect(text).not.toContain("Removable on"); }); - it("no guard: the Guard row is 0 with no parenthesis", () => { - const verdicts = { - "temporal-compat-check": check([], { - stillNeeded: 16, - removable: 0, - guard: 0, - }), - "temporal-oracle": oracle(), - }; - expect(oracleSummary(verdicts).split("\n")).toContain("| Guard | 0 |"); - }); - - it("two guards list each id with its through", () => { - const second = { - ...guardWorkaround, - id: "D12", - guard: { - ...guardWorkaround.guard, - package: "temporal-spec", - through: "1.2.3", - }, - }; - const verdicts = { - "temporal-compat-check": check([guardWorkaround, second], { - stillNeeded: 14, - removable: 0, - guard: 2, - }), - "temporal-oracle": oracle(), - }; - expect(oracleSummary(verdicts).split("\n")).toContain( - "| Guard | 2 (D10, through @js-temporal/polyfill 0.5.1; D12, through temporal-spec 1.2.3) |", - ); - }); - it("a stale snapshot says to run pnpm compat:snapshot", () => { const verdicts = { "temporal-compat-check": check( - [guardWorkaround], - { stillNeeded: 15, removable: 0, guard: 1 }, + [stillNeededWorkaround], + { stillNeeded: 15, removable: 0 }, false, ), "temporal-oracle": oracle(), @@ -664,7 +610,7 @@ describe("summaryMarkdown: temporal-oracle", () => { expect(text).not.toContain("Snapshot:"); expect(text).toContain("| Comparisons | 410000 |"); expect(text).toContain( - "@js-temporal/polyfill 0.5.1 · Node v24.11.0 · ICU 77.1 · Chromium 152.0.7444.0", + "temporal-polyfill 1.0.8 · Node v24.11.0 · ICU 77.1 · Chromium 152.0.7444.0", ); }); @@ -672,9 +618,6 @@ describe("summaryMarkdown: temporal-oracle", () => { const text = oracleSummary(clean(), { removable: "D2" }); expect(text.split("\n")).toContain("**Dry run:** --force-removable=D2"); expect(text).toContain("| Removable | 0 |"); - expect(text).toContain( - "| Guard | 1 (D10, through @js-temporal/polyfill 0.5.1) |", - ); expect(text).not.toContain("Removable: D2"); }); @@ -854,17 +797,41 @@ describe("summaryMarkdown: temporal-oracle", () => { describe("summaryMarkdown: temporal polyfill swap", () => { const block = (text: string) => { - const start = text.indexOf("### Temporal polyfill swap"); + const start = text.indexOf("### Temporal polyfill upgrade check"); const end = text.indexOf("\n\n**", start); return text.slice(start, end === -1 ? undefined : end); }; const swapOnly = (over: Record) => block(oracleSummary({ ...clean(), ...over })); - it("a ready run says Ready to swap, with the version, a row per leg and the sweep line", () => { + it("a ready run says Ready to raise the pin, with the version, a row per leg and the sweep line", () => { expect(block(oracleSummary(clean()))).toBe(SWAP_BLOCK.join("\n")); }); + it("swap legs skipped on purpose: the block says the pin is the newest release, with no Not ready line", () => { + const { + ["temporal-polyfill-swap-node"]: _n, + ["temporal-polyfill-swap-chromium"]: _c, + ["temporal-polyfill-swap-firefox"]: _f, + ["temporal-polyfill-swap-webkit"]: _w, + ...rest + } = clean(); + const text = block( + summaryMarkdown( + "temporal-oracle", + rest as never, + {}, + [], + undefined, + [], + true, + ), + ); + expect(text).toBe( + "### Temporal polyfill upgrade check\n\nSkipped: the pinned temporal-polyfill is the newest release, so there is nothing to check.", + ); + }); + it("a failing leg is not ready, with the reason, and its counts print", () => { const text = swapOnly({ "temporal-polyfill-swap-webkit": swap("webkit", { @@ -880,7 +847,7 @@ describe("summaryMarkdown: temporal polyfill swap", () => { }), }); expect(text).toContain( - "temporal-polyfill 1.0.7 — Not ready: temporal-polyfill-swap-webkit: 5 tests fail on the swap", + "temporal-polyfill 1.0.7 — Not ready: temporal-polyfill-swap-webkit: 5 tests fail on the candidate", ); expect(text.split("\n")).toContain("| webkit | 71337 | 5 | 2 |"); }); diff --git a/apps/dox/scripts/canary/canary-verdict.test.ts b/apps/dox/scripts/canary/canary-verdict.test.ts index 31ef74c1b..a35385705 100644 --- a/apps/dox/scripts/canary/canary-verdict.test.ts +++ b/apps/dox/scripts/canary/canary-verdict.test.ts @@ -24,30 +24,15 @@ import { */ const runtime = { polyfill: "0.5.1", node: "v24.11.0", icu: "77.1" }; -const guard = { - package: "@js-temporal/polyfill", - through: "0.5.1", - reason: "reason text", -}; - interface GroupInput { defects: string[]; - state: "still-needed" | "removable" | "guard" | "out-of-scope"; - guardLapsed?: boolean; - withGuard?: boolean; + state: "still-needed" | "removable" | "out-of-scope"; probes?: number; failing?: number; } /** One group as `check` holds it after `withStates`. */ -function group({ - defects, - state, - guardLapsed = false, - withGuard = false, - probes = 2, - failing = 0, -}: GroupInput) { +function group({ defects, state, probes = 2, failing = 0 }: GroupInput) { const id = defects.join("+"); return { workaround: { @@ -55,12 +40,10 @@ function group({ title: `${id} — title`, trigger: `${id} trigger`, steps: [`${id} step one`, `${id} step two`], - ...(withGuard ? { guard } : {}), }, results: Array.from({ length: probes }, () => ({})), passing: probes - failing, state, - guardLapsed, }; } @@ -68,7 +51,7 @@ describe("compatCheckVerdict", () => { const groups = [ group({ defects: ["D1"], state: "still-needed", probes: 3, failing: 2 }), group({ defects: ["D3", "D4"], state: "removable" }), - group({ defects: ["D10"], state: "guard", withGuard: true }), + group({ defects: ["D9"], state: "out-of-scope" }), ]; const verdict = compatCheckVerdict({ runtime, @@ -83,13 +66,12 @@ describe("compatCheckVerdict", () => { expect(verdict.runtime).toEqual(runtime); }); - it("counts a still-needed, a removable and a guard group", () => { + it("counts a still-needed, a removable and an out-of-scope group", () => { expect(verdict.counts).toEqual({ workarounds: 3, stillNeeded: 1, removable: 1, - guard: 1, - outOfScope: 0, + outOfScope: 1, }); }); @@ -105,7 +87,6 @@ describe("compatCheckVerdict", () => { workarounds: 1, stillNeeded: 0, removable: 0, - guard: 0, outOfScope: 1, }); expect(out.workarounds[0].state).toBe("out-of-scope"); @@ -116,7 +97,7 @@ describe("compatCheckVerdict", () => { expect(verdict.workarounds.map((w: { id: string }) => w.id)).toEqual([ "D1", "D3+D4", - "D10", + "D9", ]); expect(verdict.workarounds[1].defects).toEqual(["D3", "D4"]); }); @@ -140,33 +121,6 @@ describe("compatCheckVerdict", () => { ).toEqual(groups.map((g) => g.workaround.steps)); }); - it("carries a guard that holds with lapsed false", () => { - expect(verdict.workarounds[2].state).toBe("guard"); - expect(verdict.workarounds[2].guard).toEqual({ ...guard, lapsed: false }); - }); - - it("carries a lapsed guard on a removable group", () => { - const lapsed = compatCheckVerdict({ - runtime, - groups: [ - group({ - defects: ["D10"], - state: "removable", - guardLapsed: true, - withGuard: true, - }), - ], - snapshotCurrent: true, - }); - expect(lapsed.workarounds[0].state).toBe("removable"); - expect(lapsed.workarounds[0].guard?.lapsed).toBe(true); - }); - - it("has no guard property on a group without one", () => { - expect("guard" in verdict.workarounds[0]).toBe(false); - expect("guard" in verdict.workarounds[1]).toBe(false); - }); - it.each` snapshotCurrent ${true} @@ -188,7 +142,7 @@ describe("browserCompatVerdict", () => { const groups = [ group({ defects: ["D1"], state: "still-needed", probes: 3, failing: 2 }), group({ defects: ["D3", "D4"], state: "removable" }), - group({ defects: ["D10"], state: "guard", withGuard: true }), + group({ defects: ["D9"], state: "out-of-scope" }), ]; const browserRuntime = { polyfill: "0.5.1", @@ -547,7 +501,8 @@ describe("polyfillSwapVerdict", () => { const input = { leg: "node" as const, version: "1.0.7", - entry: "temporal-polyfill/full/implementation", + pinned: "1.0.6", + entry: "temporal-polyfill-candidate/full/implementation", entryLoaded: true, runtime: { node: "26.12.1", @@ -575,6 +530,7 @@ describe("polyfillSwapVerdict", () => { "status", "leg", "version", + "pinned", "entry", "entryLoaded", "runtime", diff --git a/apps/dox/scripts/canary/native-suite-compat.test.ts b/apps/dox/scripts/canary/native-suite-compat.test.ts index 62aaae4ba..db6f1b7d5 100644 --- a/apps/dox/scripts/canary/native-suite-compat.test.ts +++ b/apps/dox/scripts/canary/native-suite-compat.test.ts @@ -1,10 +1,4 @@ -import { - existsSync, - mkdirSync, - mkdtempSync, - rmSync, - writeFileSync, -} from "node:fs"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -34,8 +28,7 @@ import { const PATHS = { dist: "/repo/packages/gmt/dist", - polyfill: "/repo/node_modules/@js-temporal/polyfill/dist/index.esm.js", - jsbi: "/repo/node_modules/jsbi/dist/jsbi.mjs", + polyfill: "export const Temporal = {};\n", }; /** One passing probe per defect every workaround group names, on the given engine. */ @@ -60,11 +53,11 @@ const groupOf = (groups: ReturnType, id: string) => { describe("compatPage", () => { const page = compatPage(); - it("maps the polyfill's bare imports onto the page's own paths", () => { + it("maps the one specifier the compiled repros import onto the page's own bundle", () => { const map = /