Skip to content

[jsweep] Clean action_conclusion_otlp.cjs#24669

Merged
pelikhan merged 1 commit intomainfrom
jsweep/clean-action-conclusion-otlp-f9dae01e082ecdbe
Apr 5, 2026
Merged

[jsweep] Clean action_conclusion_otlp.cjs#24669
pelikhan merged 1 commit intomainfrom
jsweep/clean-action-conclusion-otlp-f9dae01e082ecdbe

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 5, 2026

Summary

Cleaned action_conclusion_otlp.cjs — a Node.js context file that sends OTLP conclusion spans for GitHub Actions jobs.

Context type

Node.js (not github-script) — uses console.log, process.env, and CJS require.

Changes made

action_conclusion_otlp.cjs:

  • Removed unused path = require("path") import
  • Simplified dependency from require(path.join(__dirname, "send_otlp_span.cjs")) (dynamic path construction inside function) to require("./send_otlp_span.cjs") at module top level
  • Changed from destructuring (const { sendJobConclusionSpan }) to module reference (const sendOtlpSpan = require(...)) so the dependency can be properly patched in tests — this is idiomatic CJS mock-patching style

action_conclusion_otlp.test.cjs (new file — 11 tests):

  • Uses createRequire + direct module-export patching to reliably mock CJS dependencies (avoids the vi.mock() / native-require cache conflict)
  • Tests cover:
    • Early return when OTEL_EXPORTER_OTLP_ENDPOINT is not set
    • sendJobConclusionSpan is NOT called when skipping
    • sendJobConclusionSpan IS called when endpoint is set
    • Correct default span name (gh-aw.job.conclusion)
    • Span name with INPUT_JOB_NAME set (gh-aw.<name>.conclusion)
    • Log messages at each stage
    • Error propagation from sendJobConclusionSpan

Test improvements

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

✅ All validation checks passed

Check Status
npm run format:cjs
npm run lint:cjs
npm run typecheck
npm run test:js -- --no-file-parallelism ✅ (11/11 new tests pass, full suite passes)

Generated by jsweep - JavaScript Unbloater · ● 5.1M ·

  • expires on Apr 7, 2026, 4:47 AM UTC

- Remove unused path require; use relative require('./send_otlp_span.cjs')
- Hold module reference (avoid destructuring) to enable CJS mock patching in tests
- Add 11 comprehensive tests covering: skip behavior, span name construction
  (default and INPUT_JOB_NAME), logging, and error propagation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review April 5, 2026 04:58
Copilot AI review requested due to automatic review settings April 5, 2026 04:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the OTLP job-conclusion span sender to simplify its dependency loading and adds targeted unit tests around skip/call behavior, span naming, logging, and error propagation.

Changes:

  • Simplified action_conclusion_otlp.cjs to use a direct relative require("./send_otlp_span.cjs") and call via module reference.
  • Added action_conclusion_otlp.test.cjs with unit tests using CJS export patching to mock sendJobConclusionSpan.
  • Expanded assertions around logging, span name construction, and error propagation.
Show a summary per file
File Description
actions/setup/js/action_conclusion_otlp.cjs Removes unused path logic and simplifies how send_otlp_span.cjs is referenced/called.
actions/setup/js/action_conclusion_otlp.test.cjs Adds unit tests that mock the CJS dependency and validate skip/call/log/span-name/error behavior.

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_conclusion_otlp.cjs:32

  • send_otlp_span.cjs is now required at module load time, so it will be loaded even when OTEL_EXPORTER_OTLP_ENDPOINT is unset and run() early-returns. If you want to keep the skip path as lightweight as possible, consider moving the require("./send_otlp_span.cjs") into run() after the endpoint check while still calling it via module.sendJobConclusionSpan(...) (avoid destructuring) to preserve test patchability.
const sendOtlpSpan = require("./send_otlp_span.cjs");

/**
 * Send the OTLP job-conclusion span.  Non-fatal: all errors are silently
 * swallowed.
  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment on lines +1 to +5
// @ts-check
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { createRequire } from "module";

// Use CJS require so we share the same module cache as action_conclusion_otlp.cjs
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says there were "0 tests" before, but actions/setup/js/action_otlp.test.cjs already contains an action_conclusion_otlp run() test suite. Consider updating the PR description to reflect that this PR adds additional/targeted coverage rather than introducing the first tests.

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit ec6a4de into main Apr 5, 2026
67 checks passed
@pelikhan pelikhan deleted the jsweep/clean-action-conclusion-otlp-f9dae01e082ecdbe branch April 5, 2026 05:04
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.

2 participants