Skip to content

fix: make daily AIC guardrail exceedance test reliable in CI#38707

Closed
Copilot wants to merge 1 commit into
mainfrom
copilot/fix-js-tests-failure
Closed

fix: make daily AIC guardrail exceedance test reliable in CI#38707
Copilot wants to merge 1 commit into
mainfrom
copilot/fix-js-tests-failure

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The main() marks the step failed when the daily AI Credits guardrail is exceeded test was flaky in CI because it called vi.doMock("@actions/artifact") after the source module was already loaded in beforeEach. In GitHub Actions, @actions/artifact is ESM-only and Node's native ESM cache can serve the real module, bypassing Vitest's mock registry — causing the real listArtifacts() to fail silently and leave daily_effective_workflow_exceeded at "false".

Changes

  • check_daily_aic_workflow_guardrail.test.cjs — restructure the guardrail exceedance test to use the canonical Vitest vi.doMock pattern: register the mock first, then vi.resetModules() + re-import the source, then call localExports.main().
// Before: doMock called after module already loaded in beforeEach
vi.doMock("@actions/artifact", () => ({ ... }));
// ...
await expect(exports.main()).resolves.toBeUndefined();

// After: doMock → resetModules → re-import → call
vi.doMock("@actions/artifact", () => ({ ... }));
vi.resetModules();
const mod = await import("./check_daily_aic_workflow_guardrail.cjs");
const localExports = mod.default || mod;
// ...
await expect(localExports.main()).resolves.toBeUndefined();

This guarantees import("@actions/artifact") inside getArtifactClient() consults Vitest's mock registry before Node's native ESM cache.

… pattern

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title fix: make daily AIC guardrail exceedance test reliable with vi.doMock pattern fix: make daily AIC guardrail exceedance test reliable in CI Jun 11, 2026
Copilot AI requested a review from pelikhan June 11, 2026 19:08
@pelikhan pelikhan marked this pull request as ready for review June 11, 2026 20:09
Copilot AI review requested due to automatic review settings June 11, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a CI flake in the daily AI Credits (AIC) guardrail exceedance test by ensuring Vitest’s module mocking is applied before the source module is loaded, avoiding cases where Node’s ESM cache can bypass the mock for @actions/artifact in GitHub Actions.

Changes:

  • Updates the exceedance test to register vi.doMock("@actions/artifact") before re-importing the source module.
  • Adds vi.resetModules() + a fresh dynamic import() of check_daily_aic_workflow_guardrail.cjs, and runs assertions against the re-imported main().
Show a summary per file
File Description
actions/setup/js/check_daily_aic_workflow_guardrail.test.cjs Reorders mocking + module loading to make the @actions/artifact mock reliably apply in CI.

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: 0

@pelikhan pelikhan closed this Jun 11, 2026
@github-actions github-actions Bot deleted the copilot/fix-js-tests-failure branch June 19, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants