Repository navigation
[jsweep] Clean action_setup_otlp.cjs and add comprehensive tests - #26564
github-actions[bot] wants to merge 4 commits into
Conversation
- Move require('./send_otlp_span.cjs') to module level (consistent with
action_conclusion_otlp.cjs)
- Remove path.join(__dirname, ...) for require (unnecessary in CJS)
- Use sendOtlpSpan.method() pattern instead of destructuring at call site,
enabling vitest module-patch mocking
- Add comprehensive test file with 32 tests covering:
- OTLP endpoint present/absent behavior
- INPUT_TRACE_ID handling (including lowercase normalization, hyphen form)
- INPUT_JOB_NAME propagation
- SETUP_START_MS parsing
- GITHUB_OUTPUT writing (valid/invalid trace IDs)
- GITHUB_ENV writing (trace ID, span ID, job start ms)
- Error propagation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Refactors the setup-side OTLP span sender to be more testable/consistent with the conclusion span implementation, and adds a dedicated test suite for action_setup_otlp.cjs.
Changes:
- Move
send_otlp_span.cjsimport to module scope and switch tosendOtlpSpan.method()access to enable module-patching mocks. - Remove the dynamic
require()/pathusage insiderun(). - Add a new
action_setup_otlp.test.cjsfile with broad coverage of env/input/output behavior.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/action_setup_otlp.cjs | Simplifies/standardizes OTLP helper loading and call sites to support mocking and consistency. |
| actions/setup/js/action_setup_otlp.test.cjs | Adds a focused test suite validating logging, env/input handling, and GITHUB_OUTPUT/GITHUB_ENV writes. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
actions/setup/js/action_setup_otlp.test.cjs:195
- This test doesn't assert any behavior from
run(): it setsprocess.env.INPUT_JOB_NAMEand then expects it to still be set afterwards, which would pass even ifrun()did nothing. If the goal is to validate input normalization, consider setting only the hyphen form (INPUT_JOB-NAME) and asserting thatrun()populatesprocess.env.INPUT_JOB_NAME(or otherwise asserting an observable effect of job-name handling).
describe("INPUT_JOB_NAME handling", () => {
it("should set INPUT_JOB_NAME env var when provided", async () => {
process.env.INPUT_JOB_NAME = "agent";
await run();
expect(process.env.INPUT_JOB_NAME).toBe("agent");
});
});
- Files reviewed: 2/2 changed files
- Comments generated: 2
| } | ||
|
|
||
| const { traceId, spanId } = await sendJobSetupSpan({ startMs, traceId: inputTraceId || undefined }); | ||
| const { traceId, spanId } = await sendOtlpSpan.sendJobSetupSpan({ startMs, traceId: inputTraceId || undefined }); | ||
|
|
||
| console.log(`[otlp] resolved trace-id=${traceId}`); |
There was a problem hiding this comment.
The JSDoc for run() says errors are "silently swallowed", but await sendOtlpSpan.sendJobSetupSpan(...) (and the subsequent file writes) will reject/throw when run() is imported and called. Either update the comment to clarify that callers (e.g. actions/setup/index.js) swallow errors, or wrap the body of run() in a try/catch if run() itself is intended to be non-fatal.
See below for a potential fix:
try {
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
const startMs = parseInt(process.env.SETUP_START_MS || "0", 10);
// Explicitly read INPUT_TRACE_ID and pass it as options.traceId so the
// activation job's trace ID is used even when process.env propagation
// through GitHub Actions expression evaluation is unreliable.
const inputTraceId = getActionInput("TRACE_ID").toLowerCase();
if (inputTraceId) {
console.log(`[otlp] INPUT_TRACE_ID=${inputTraceId} (will reuse activation trace)`);
} else {
console.log("[otlp] INPUT_TRACE_ID not set, a new trace ID will be generated");
}
// Normalize to the canonical underscore form so sendJobSetupSpan (which
// reads process.env.INPUT_JOB_NAME) always finds the value.
const inputJobName = getActionInput("JOB_NAME");
if (inputJobName) {
process.env.INPUT_JOB_NAME = inputJobName;
}
if (!endpoint) {
console.log("[otlp] OTEL_EXPORTER_OTLP_ENDPOINT not set, skipping setup span");
} else {
console.log(`[otlp] sending setup span to ${endpoint}`);
}
const { traceId, spanId } = await sendOtlpSpan.sendJobSetupSpan({ startMs, traceId: inputTraceId || undefined });
console.log(`[otlp] resolved trace-id=${traceId}`);
if (endpoint) {
console.log(`[otlp] setup span sent (traceId=${traceId}, spanId=${spanId})`);
}
// Always expose trace ID as a step output for cross-job correlation, even
// when OTLP is not configured. This ensures needs.*.outputs.setup-trace-id
// is populated for downstream jobs regardless of observability configuration.
if (sendOtlpSpan.isValidTraceId(traceId) && process.env.GITHUB_OUTPUT) {
appendFileSync(process.env.GITHUB_OUTPUT, `trace-id=${traceId}\n`);
console.log(`[otlp] trace-id=${traceId} written to GITHUB_OUTPUT`);
}
// Always propagate trace/span context to subsequent steps in this job so
// that the conclusion span can find the same trace ID.
if (process.env.GITHUB_ENV) {
if (sendOtlpSpan.isValidTraceId(traceId)) {
appendFileSync(process.env.GITHUB_ENV, `GITHUB_AW_OTEL_TRACE_ID=${traceId}\n`);
console.log(`[otlp] GITHUB_AW_OTEL_TRACE_ID written to GITHUB_ENV`);
}
if (sendOtlpSpan.isValidSpanId(spanId)) {
appendFileSync(process.env.GITHUB_ENV, `GITHUB_AW_OTEL_PARENT_SPAN_ID=${spanId}\n`);
console.log(`[otlp] GITHUB_AW_OTEL_PARENT_SPAN_ID written to GITHUB_ENV`);
}
// Propagate setup-end timestamp so the conclusion span can measure actual
// job execution duration (setup-end → conclusion-start).
const setupEndMs = Math.floor(nowMs());
appendFileSync(process.env.GITHUB_ENV, `GITHUB_AW_OTEL_JOB_START_MS=${setupEndMs}\n`);
console.log(`[otlp] GITHUB_AW_OTEL_JOB_START_MS written to GITHUB_ENV`);
}
} catch (_) {}
| // Clean up temp files | ||
| if (existsSync(githubOutputPath)) unlinkSync(githubOutputPath); | ||
| if (existsSync(githubEnvPath)) unlinkSync(githubEnvPath); | ||
| }); |
There was a problem hiding this comment.
mkdtempSync(...) creates a unique temp directory per test, but the afterEach only unlinks the two files and never removes tempDir. This will leave a growing number of empty directories under the OS temp folder across the test suite run. Consider removing the directory in afterEach (e.g. rmSync(tempDir, { recursive: true, force: true })).
This issue also appears on line 187 of the same file.
🧪 Test Quality Sentinel ReportTest Quality Score: 52/100🔶 Needs improvement — significant low-value tests detected
Test Classification DetailsView all 32 test classifications
Flagged Tests — Requires Review
|
There was a problem hiding this comment.
❌ Test Quality Sentinel: 52/100. 50% of new tests are classified as low-value implementation tests, exceeding the 30% threshold. The primary issues are 8+ log-only assertion tests and 3 mock-argument-only tests that duplicate behavioral signal already covered by the file-output assertions. Please review the flagged tests in the comment above and consolidate implementation tests into the existing behavioral tests.
|
@copilot Review all comments |
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/2d488966-60ba-4aa4-9b81-346dda9afbeb Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
This reverts commit e81880d. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/2d488966-60ba-4aa4-9b81-346dda9afbeb Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Reviewed all comments and applied the actionable fixes in commit 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
action_setup_otlp.cjs(Node.js context) and added a comprehensive test file with 32 tests.Changes to
action_setup_otlp.cjsContext: Node.js (runs directly via
node action_setup_otlp.cjsfromsetup.shandactions/setup/index.js)require('./send_otlp_span.cjs')to module level — consistent withaction_conclusion_otlp.cjspatternpath.join(__dirname, ...)for the require — unnecessary in CommonJS;"./send_otlp_span.cjs"resolves correctlypathmodule import — no longer neededsendOtlpSpan.method()access pattern instead of destructuring at call site — this enables vitest module-patch mocking (same pattern asaction_conclusion_otlp.cjs)The dynamic
require()insiderun()was unusual and prevented standard mock patterns. The refactor makes the code consistent with the sibling file and testable.New Test File:
action_setup_otlp.test.cjs32 tests covering all code paths:
Tests use real temp files for
GITHUB_OUTPUT/GITHUB_ENV(realistic, no fs mocking needed) and module-level patching forsendJobSetupSpan.Validation
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓npm run test:js -- action_setup_otlp→ 32/32 passed ✓