Skip to content

[jsweep] Clean action_setup_otlp.cjs#25237

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
jsweep/clean-action-setup-otlp-9c0df9c2a0d64fe3
Closed

[jsweep] Clean action_setup_otlp.cjs#25237
github-actions[bot] wants to merge 1 commit intomainfrom
jsweep/clean-action-setup-otlp-9c0df9c2a0d64fe3

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Apr 8, 2026

Summary

Cleaned action_setup_otlp.cjs (Node.js context) by improving testability and adding a comprehensive test suite.

Context Type

Node.js — This file runs directly via node action_setup_otlp.cjs from setup.sh or through actions/setup/index.js.

Changes

action_setup_otlp.cjs

  • Moved dynamic require() to module level: The require(path.join(__dirname, "send_otlp_span.cjs")) inside run() was moved to a top-level const sendOtlpSpan = require("./send_otlp_span.cjs"). This mirrors the pattern in action_conclusion_otlp.cjs and enables tests to patch module exports via the shared CJS module cache.
  • Switched appendFileSync pattern: Changed const { appendFileSync } = require("fs") (destructured, un-mockable) to const fs = require("fs") with fs.appendFileSync(...) calls. This allows vi.spyOn(fsMod, "appendFileSync") to intercept calls in tests.
  • Removed path require: No longer needed after eliminating the dynamic path.join(__dirname, ...) require.
  • All logic and behavior preserved exactly.

action_setup_otlp.test.cjs (new file)

Added 29 test cases covering:

Group Tests
Module export Exports run as a function
No OTEL endpoint Logs skip message, still calls sendJobSetupSpan, no span-sent log
OTEL endpoint set Logs endpoint URL, calls sendJobSetupSpan, logs span sent with IDs
INPUT_TRACE_ID Lowercase propagation, undefined when not set, both env var forms, log messages
SETUP_START_MS Parsed correctly, 0 default, empty string default
GITHUB_OUTPUT Writes trace-id, logs write, skips when not set, skips when traceId invalid
GITHUB_ENV Writes all three vars, skips when not set, skips invalid trace/span IDs, logs writes
Error handling Propagates errors from sendJobSetupSpan

Test Improvements

  • Before: 0 tests
  • After: 29 tests covering all code paths

Validation ✅

All four checks passed:

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js -- --no-file-parallelism action_setup_otlp → 29/29 passed ✓

Generated by jsweep - JavaScript Unbloater · ● 2.6M ·

  • expires on Apr 10, 2026, 4:40 AM UTC

- Move dynamic require() of send_otlp_span.cjs from inside run() to module
  level, enabling consistent testability via CJS module cache patching
- Change destructured appendFileSync to fs.appendFileSync pattern so tests
  can spy on the function through the shared module reference
- Remove unused path require (no longer needed after top-level require)
- Add comprehensive test file with 29 test cases covering:
  - OTEL endpoint present/absent behavior
  - INPUT_TRACE_ID propagation (including hyphen form)
  - SETUP_START_MS parsing
  - GITHUB_OUTPUT trace-id writing
  - GITHUB_ENV trace/span/timestamp writing
  - Error propagation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant