[jsweep] Clean action_conclusion_otlp.test.cjs#27144
Conversation
- Replace verbose manual env backup/restore with MANAGED_ENV_VARS array + forEach pattern - Add vi.unstubAllEnvs() to afterEach for consistent cleanup - Add missing edge-case test: negative GITHUB_AW_OTEL_JOB_START_MS → startMs: undefined - 17 tests now pass (was 16) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Great work from the
|
There was a problem hiding this comment.
Pull request overview
This PR cleans up the Vitest suite for action_conclusion_otlp.cjs by simplifying environment variable management and adding an extra edge-case test around invalid job start timestamps.
Changes:
- Replaced verbose manual env backup/restore with a managed env-var list and loop-based cleanup.
- Added
vi.unstubAllEnvs()inafterEachalongsidevi.restoreAllMocks(). - Added a new test asserting negative
GITHUB_AW_OTEL_JOB_START_MSresults instartMs: undefined.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/action_conclusion_otlp.test.cjs | Refactors env handling/cleanup and adds a negative timestamp test for startMs propagation. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.spyOn(console, "log").mockImplementation(() => {}); | ||
| mockSendJobConclusionSpan.mockResolvedValue(undefined); | ||
| // Patch the shared CJS exports object — run() accesses this at call time | ||
| sendOtlpModule.sendJobConclusionSpan = mockSendJobConclusionSpan; | ||
|
|
||
| originalEnv = { | ||
| OTEL_EXPORTER_OTLP_ENDPOINT: process.env.OTEL_EXPORTER_OTLP_ENDPOINT, | ||
| INPUT_JOB_NAME: process.env.INPUT_JOB_NAME, | ||
| "INPUT_JOB-NAME": process.env["INPUT_JOB-NAME"], | ||
| GITHUB_AW_OTEL_JOB_START_MS: process.env.GITHUB_AW_OTEL_JOB_START_MS, | ||
| }; | ||
| delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT; | ||
| delete process.env.INPUT_JOB_NAME; | ||
| delete process.env["INPUT_JOB-NAME"]; | ||
| delete process.env.GITHUB_AW_OTEL_JOB_START_MS; | ||
| MANAGED_ENV_VARS.forEach(key => delete process.env[key]); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| vi.unstubAllEnvs(); | ||
| sendOtlpModule.sendJobConclusionSpan = originalSendJobConclusionSpan; | ||
|
|
||
| if (originalEnv.OTEL_EXPORTER_OTLP_ENDPOINT !== undefined) { | ||
| process.env.OTEL_EXPORTER_OTLP_ENDPOINT = originalEnv.OTEL_EXPORTER_OTLP_ENDPOINT; | ||
| } else { | ||
| delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT; | ||
| } | ||
| if (originalEnv.INPUT_JOB_NAME !== undefined) { | ||
| process.env.INPUT_JOB_NAME = originalEnv.INPUT_JOB_NAME; | ||
| } else { | ||
| delete process.env.INPUT_JOB_NAME; | ||
| } | ||
| if (originalEnv["INPUT_JOB-NAME"] !== undefined) { | ||
| process.env["INPUT_JOB-NAME"] = originalEnv["INPUT_JOB-NAME"]; | ||
| } else { | ||
| delete process.env["INPUT_JOB-NAME"]; | ||
| } | ||
| if (originalEnv.GITHUB_AW_OTEL_JOB_START_MS !== undefined) { | ||
| process.env.GITHUB_AW_OTEL_JOB_START_MS = originalEnv.GITHUB_AW_OTEL_JOB_START_MS; | ||
| } else { | ||
| delete process.env.GITHUB_AW_OTEL_JOB_START_MS; | ||
| } | ||
| MANAGED_ENV_VARS.forEach(key => delete process.env[key]); | ||
| }); |
There was a problem hiding this comment.
The new env cleanup deletes the managed variables in beforeEach/afterEach without restoring their prior values. If any of these env vars are set by the test runner/CI (or by other tests running in the same Vitest worker), this file will permanently unset them for subsequent tests, causing cross-test flakiness. Consider capturing the original values for MANAGED_ENV_VARS at the start of each test (or suite) and restoring them in afterEach, or switch the tests to use vi.stubEnv for all env mutations so vi.unstubAllEnvs() actually reverts changes.
🧪 Test Quality Sentinel ReportTest Quality Score: 100/100✅ Excellent test quality
Test Classification Details
Analysis NotesThe bulk of this PR is a cleanup refactor of the
The refactoring is functionally equivalent and improves maintainability. No behavioral changes to existing tests. The one new test (
Language SupportTests analyzed:
Verdict
📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators. References: §24622305133
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 100/100. Test quality is excellent — 0% of new tests are implementation tests (threshold: 30%). The one new test is a well-targeted edge case (negative GITHUB_AW_OTEL_JOB_START_MS), and the rest of the PR is a clean refactor of env var management.
|
@copilot review all comments and fix https://github.com/github/gh-aw/actions/runs/24622305137/job/71995166799 |
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d44331f7-7296-49fe-9754-5ac197e47c5b Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d44331f7-7296-49fe-9754-5ac197e47c5b Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in I reviewed the comments and investigated the linked CI failure log. I updated Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/fc5f39ea-bc2b-4b3d-be8d-271e2ea9e988 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/fc5f39ea-bc2b-4b3d-be8d-271e2ea9e988 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in I reproduced the failing CI case from shard 4 and made the test deterministic for pull_request environments by setting and cleaning up Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
Cleaned up
action_conclusion_otlp.test.cjs(Node.js context — not github-script).Changes
Test file improvements (
action_conclusion_otlp.test.cjs):originalEnvobject + conditional restore code with aMANAGED_ENV_VARSarray and aforEachloop, reducing boilerplate by ~20 linesvi.unstubAllEnvs()toafterEachfor consistent cleanup alongsidevi.restoreAllMocks()GITHUB_AW_OTEL_JOB_START_MSas a negative number (-1000) should producestartMs: undefined(negative values are not valid epoch timestamps)The source file (
action_conclusion_otlp.cjs) was already clean with@ts-check, proper JSDoc types, and no unnecessary try/catch blocks — no changes needed there.Test improvements
Validation ✅
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓npm run test:js -- action_conclusion_otlp→ 17/17 passed ✓