-
Notifications
You must be signed in to change notification settings - Fork 5
Harden test determinism and restore frontend CI gating #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Phase 03 Checklist - Test Determinism and CI Hardening | ||
|
|
||
| Source plan: `docs/plans/phase-03-test-determinism-and-ci-hardening.md` | ||
|
|
||
| ## Checklist | ||
|
|
||
| - [x] C01 `[backend]` Add `src/tests/backend/setup-env.ts` to load `example.env`, inject missing required env keys into `process.env`, and set deterministic non-default test values for `*SECRET*`/`*PASSWORD*` keys. | ||
| - [x] C02 `[backend]` Wire backend Jest env bootstrap by adding `src/tests/backend/setup-env.ts` to `setupFiles` in `jest.backend.config.ts`. Depends on: C01. | ||
| - [x] C03 `[backend]` Refactor `src/tests/backend/secrets.test.ts` to remove hard `.env exists` failure and assert effective env values instead of filesystem state; include non-blocking local guidance when `.env` is absent. Depends on: C02. | ||
| - [x] C04 `[frontend]` Refactor `longFormatDate` locale assertions in `src/tests/frontend/frontend-utilities.test.ts` to deterministic structural checks (date/time parts) instead of exact locale prose strings, while keeping the full existing locale matrix. | ||
| - [x] C05 `[frontend]` Add locale fallback guardrails in `src/tests/frontend/frontend-utilities.test.ts` for every locale in the matrix using `Intl.DateTimeFormat.supportedLocalesOf` and resolved locale-family checks. Depends on: C04. | ||
| - [x] C06 `[frontend]` Normalize locale-test fixtures in `src/tests/frontend/frontend-utilities.test.ts` to UTC-stable values (`Date.UTC(...)` and/or ISO `...Z`) and keep at least one integration-style localized rendering check. Depends on: C04. | ||
| - [x] C07 `[config]` Update frontend test script wiring in `package.json` so frontend locale tests run under `TZ=UTC` in deterministic paths, and add `cross-env` if required for cross-platform shell compatibility. Depends on: C06. | ||
| - [x] C08 `[ci]` Update `.github/workflows/netlify-api-test.yml` to remove `.env` bootstrap from backend test execution path (`node ./scripts/createTestEnv.mjs`) and run backend tests using the Jest-injected env path. Depends on: C02, C03. | ||
| - [x] C09 `[ci]` Set `TZ=UTC` for test execution in `.github/workflows/netlify-api-test.yml` and keep existing MongoDB binary pinning behavior. Depends on: C08. | ||
| - [x] C10 `[ci]` Restore required frontend test gating in `.github/workflows/netlify-api-test.yml` by running `yarn test:frontend` in required CI alongside backend tests. Depends on: C09. | ||
| - [x] C11 `[docs]` Document deterministic test expectations and command sequence in `README.md`, including: backend tests do not require `.env` on disk, timezone policy is `TZ=UTC`, and frontend i18n coverage remains full-matrix. Depends on: C03, C10. | ||
|
|
||
| ## Behavior Slices | ||
|
|
||
| - Goal: Make backend tests deterministic and independent of local `.env` files. | ||
| Items: C01, C02, C03, C08 | ||
| Type: behavior | ||
|
|
||
| - Goal: Keep full i18n locale coverage while making locale/date tests deterministic. | ||
| Items: C04, C05, C06, C07 | ||
| Type: behavior | ||
|
|
||
| - Goal: Restore and harden CI gating and document deterministic testing contract. | ||
| Items: C09, C10, C11 | ||
| Type: behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { readFileSync } from "fs" | ||
|
|
||
| const exampleEnvPath = `${process.cwd()}/example.env` | ||
|
|
||
| const deterministicSecretValue = (key: string) => | ||
| `test-${key.toLowerCase()}-value` | ||
|
|
||
| const isSecretOrPassword = (key: string) => | ||
| key.includes("SECRET") || key.includes("PASSWORD") | ||
|
|
||
| const parseExampleEnv = () => | ||
| readFileSync(exampleEnvPath, "utf8") | ||
| .replace(/\r/g, "\n") | ||
| .split("\n") | ||
| .map(line => line.trim()) | ||
| .filter(line => line.length > 0) | ||
| .filter(line => !line.startsWith("#")) | ||
| .map(line => { | ||
| const separatorIndex = line.indexOf("=") | ||
| if (separatorIndex < 1) return undefined | ||
| const key = line.slice(0, separatorIndex).trim() | ||
| const value = line.slice(separatorIndex + 1).trim() | ||
| return { key, value } | ||
| }) | ||
| .filter(entry => entry !== undefined) | ||
|
|
||
| parseExampleEnv().forEach(({ key, value }) => { | ||
| if (isSecretOrPassword(key)) { | ||
| if (process.env[key] === undefined || process.env[key] === value) { | ||
| process.env[key] = deterministicSecretValue(key) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if (process.env[key] === undefined) { | ||
| process.env[key] = value | ||
| } | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.