Skip to content

[jsweep] Clean expired_entity_cleanup_helpers.cjs - #30271

Merged
pelikhan merged 2 commits into
mainfrom
jsweep/expired-entity-cleanup-helpers-65f71174a8f6c810
May 5, 2026
Merged

[jsweep] Clean expired_entity_cleanup_helpers.cjs#30271
pelikhan merged 2 commits into
mainfrom
jsweep/expired-entity-cleanup-helpers-65f71174a8f6c810

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Cleans and adds comprehensive test coverage for expired_entity_cleanup_helpers.cjs.

Context type

GitHub Actions (github-script) context — uses core global injected by the actions runtime (or shim.cjs).

Changes

expired_entity_cleanup_helpers.cjs

  • Fix /// <reference> triple-slash directive: The file had // <reference types="@actions/github-script" /> (two forward slashes), which is a plain comment and does not work as a TypeScript triple-slash directive for type resolution. Fixed to /// <reference ...> (three slashes).
  • Simplify redundant slice conditional: buildNotExpiredSection had a notExpiredEntities.length > 10 ? notExpiredEntities.slice(0, 10) : notExpiredEntities guard that is redundant — Array.slice is safe when the array is shorter than the requested count. Simplified to notExpiredEntities.slice(0, 10) directly.

expired_entity_cleanup_helpers.test.cjs (new file)

Added 26 test cases covering all exported functions:

FunctionTests
delay2
validateCreationDate5
categorizeByExpiration6
processExpiredEntities5
buildExpirationSummary6
constants2

Validation

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: all 26 tests pass ✅

Generated by jsweep - JavaScript Unbloater · ● 2.8M ·

  • expires on May 7, 2026, 4:53 AM UTC

- Fix // <reference to /// <reference triple-slash directive for proper type resolution
- Simplify redundant slice conditional in buildNotExpiredSection
- Add comprehensive test file with 26 test cases covering all exported functions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review May 5, 2026 05:26
CopilotAI review requested due to automatic review settings May 5, 2026 05:26
@github-actionsgithub-actionsBot mentioned this pull request May 5, 2026

CopilotAI 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 cleans up expired_entity_cleanup_helpers.cjs and adds a new Vitest suite for its exported helpers.

Changes:

  • Fixed the @actions/github-script triple-slash type reference in expired_entity_cleanup_helpers.cjs.
  • Simplified the buildNotExpiredSection truncation logic by always using slice(0, 10).
  • Added a new expired_entity_cleanup_helpers.test.cjs suite covering the exported helpers and constants.
Show a summary per file
FileDescription
actions/setup/js/expired_entity_cleanup_helpers.cjsSmall cleanup to type-reference metadata and not-expired summary list truncation.
actions/setup/js/expired_entity_cleanup_helpers.test.cjsNew Vitest coverage for delay, date validation, expiration categorization, processing, summaries, and constants.

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/expired_entity_cleanup_helpers.test.cjs:145

  • Because the mock always resolves to the same record and this test only checks array lengths, it would still pass if processExpiredEntities accidentally reused the first result for every entity or otherwise lost per-entity data. Returning distinct records per call would verify that each loop iteration preserves the individual processEntity result.
 const processEntity = vi.fn().mockResolvedValue({ status: "closed", record: { number: 1 } });
const { closed, skipped, failed } = await processExpiredEntities(entities, {
entityLabel: "Issue",
delayMs: 0,
processEntity,
});
expect(closed).toHaveLength(2);
expect(skipped).toHaveLength(0);
expect(failed).toHaveLength(0);
});
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +166 to 168
const list = notExpiredEntities.slice(0, 10);
if (notExpiredEntities.length > 10) {
section += `${notExpiredEntities.length} ${entityLabel.toLowerCase()}(s) not yet expired (showing first 10):\n\n`;
Comment on lines +38 to +40
const start = Date.now();
await delay(10);
expect(Date.now() - start).toBeGreaterThanOrEqual(5);
@github-actions

Copy link
Copy Markdown
ContributorAuthor

🧪 Test Quality Sentinel Report

Test Quality Score: 61/100

⚠️Acceptable — with suggestions

MetricValue
New/modified tests analyzed26
✅ Design tests (behavioral contracts)24 (92%)
⚠️ Implementation tests (low value)2 (8%)
Tests with error/edge cases12 (46%)
Duplicate test clusters0
Test inflation detected⚠️ Yes — 275 test lines vs. 2 production lines changed (137:1 ratio)
🚨 Coding-guideline violationsNone

Test Classification Details

View all 26 test classifications
TestFileClassificationNotes
delay — resolves after specified timeexpired_entity_cleanup_helpers.test.cjs✅ DesignVerifies timing promise
delay — resolves immediately for 0 msexpired_entity_cleanup_helpers.test.cjs✅ DesignEdge case: zero duration
validateCreationDate — valid ISO 8601 dateexpired_entity_cleanup_helpers.test.cjs✅ DesignHappy path
validateCreationDate — valid date-only stringexpired_entity_cleanup_helpers.test.cjs✅ DesignFormat variant
validateCreationDate — invalid date stringexpired_entity_cleanup_helpers.test.cjs✅ DesignError path
validateCreationDate — empty stringexpired_entity_cleanup_helpers.test.cjs✅ DesignEdge case
validateCreationDate — purely numeric stringexpired_entity_cleanup_helpers.test.cjs✅ DesignEdge case
categorizeByExpiration — puts expired in expired arrayexpired_entity_cleanup_helpers.test.cjs✅ DesignCore behavioral contract
categorizeByExpiration — puts non-expired in notExpired arrayexpired_entity_cleanup_helpers.test.cjs✅ DesignCore behavioral contract
categorizeByExpiration — skips invalid creation dates + warnsexpired_entity_cleanup_helpers.test.cjs✅ DesignError path + side-effect
categorizeByExpiration — skips missing expiration markers + warnsexpired_entity_cleanup_helpers.test.cjs✅ DesignError path + side-effect
categorizeByExpiration — returns now Dateexpired_entity_cleanup_helpers.test.cjs✅ DesignOutput shape contract
categorizeByExpiration — attaches expirationDateexpired_entity_cleanup_helpers.test.cjs✅ DesignOutput shape contract
processExpiredEntities — processes all and returns closedexpired_entity_cleanup_helpers.test.cjs✅ DesignCore behavioral contract
processExpiredEntities — tracks skipped separatelyexpired_entity_cleanup_helpers.test.cjs✅ DesignStatus routing
processExpiredEntities — tracks failed when throwsexpired_entity_cleanup_helpers.test.cjs✅ DesignError handling
processExpiredEntities — respects maxPerRun limitexpired_entity_cleanup_helpers.test.cjs✅ DesignBoundary: call-count maps to observable side-effect limit
processExpiredEntities — empty input returns empty arraysexpired_entity_cleanup_helpers.test.cjs✅ DesignEdge case: empty input
buildExpirationSummary — includes heading and scan summaryexpired_entity_cleanup_helpers.test.cjs✅ DesignOutput content contract
buildExpirationSummary — lists successfully closed entitiesexpired_entity_cleanup_helpers.test.cjs✅ DesignOutput content contract
buildExpirationSummary — shows failed entities when presentexpired_entity_cleanup_helpers.test.cjs✅ DesignError-path output
buildExpirationSummary — shows remaining count when > maxPerRunexpired_entity_cleanup_helpers.test.cjs✅ DesignBoundary condition output
buildExpirationSummary — shows skipped when includeSkippedHeading trueexpired_entity_cleanup_helpers.test.cjs✅ DesignFlag behavior
buildExpirationSummary — omits skipped when includeSkippedHeading falseexpired_entity_cleanup_helpers.test.cjs✅ DesignFlag behavior toggle
constants — DEFAULT_MAX_UPDATES_PER_RUN is 100expired_entity_cleanup_helpers.test.cjs⚠️ ImplementationPins a specific constant value
constants — DEFAULT_GRAPHQL_DELAY_MS is 500expired_entity_cleanup_helpers.test.cjs⚠️ ImplementationPins a specific constant value

Flagged Tests — Suggestions

⚠️constants — exports DEFAULT_MAX_UPDATES_PER_RUN as 100 / DEFAULT_GRAPHQL_DELAY_MS as 500

Classification: Implementation tests
Issue: These tests pin specific constant numeric values. They will fail whenever a developer intentionally changes a default, even if all behavioral contracts remain satisfied.
What design invariant does this test enforce? The specific exported values — not the behavior those values produce when used downstream.
What would break if deleted? Only an explicit value change would be missed, not a behavioral regression.
Suggested improvement: Either remove these tests (constants are trivially verified by reading the source), or reframe them as behavioral assertions — for example: test that processExpiredEntities with no explicit maxPerRun argument defaults to processing no more than DEFAULT_MAX_UPDATES_PER_RUN entities, which ties the constant to observable behavior.


Test Inflation Note

The formula flags test inflation because this PR adds 275 test lines while modifying only 2 production lines (ratio: 137:1 > 2:1 threshold). However, this is expected context: the PR ([jsweep]) is retroactively adding test coverage for an existing production module (expired_entity_cleanup_helpers.cjs), not testing newly written production code. The inflation penalty (−10 pts) is applied per formula but does not indicate a quality problem — adding retroactive coverage is a positive contribution.


Mocking Assessment

global.core (core.warning, core.info, etc.) is mocked via mockCore — this is the GitHub Actions runtime, which is the correct and accepted target for mocking (external I/O). The injected processEntity callback in processExpiredEntities tests is also legitimately mocked since it represents an external side-effecting function passed by callers. No internal business-logic functions are mocked without behavioral assertions. ✅


Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): 0 tests
  • 🟨 JavaScript (*.test.cjs): 26 tests (vitest)

Verdict

Check passed. Only 8% of new tests are implementation tests (threshold: 30%). The test suite provides strong behavioral coverage for expired_entity_cleanup_helpers.cjs, including error paths, boundary conditions, and side-effect verification. Minor suggestion: consider converting the two constant-value tests into behavioral assertions.


📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal values (specific constant numbers, internal call counts without behavioral effect)
  • Give false assurance: they pass even when the system is wrong
  • Break during legitimate changes even when behavior is correct

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.


References:§25359488983

🧪 Test quality analysis by Test Quality Sentinel · ● 658.9K ·

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Test Quality Sentinel: 61/100. Test quality is acceptable.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot review all comments

CopilotAI commented May 5, 2026

Copy link
Copy Markdown
Contributor

@copilot review all comments

Addressed both review findings in commit 6936fea:

  1. delay tolerance too loose — raised the lower bound from 5ms to 10ms so the assertion actually verifies the requested wait was honored (same issue on line 136 of the original draft no longer exists in the current file since processExpiredEntities tests use delayMs: 0).

  2. Truncation not exercised — added a new buildExpirationSummary test that passes 12 notExpired entries and asserts the output contains "showing first 10", includes entry Add HTTP transport capability validation and time MCP server for agentic engines #19 (the last of the first 10), and excludes entry Make compute-text step lazily inserted only when needed #21 (the 12th item).

@pelikhan
pelikhan merged commit 31547a1 into mainMay 5, 2026
@pelikhan
pelikhan deleted the jsweep/expired-entity-cleanup-helpers-65f71174a8f6c810 branch May 5, 2026 07:07
Copilot stopped work on behalf of pelikhan due to an error May 5, 2026 07:07
CopilotAI requested a review from pelikhanMay 5, 2026 07:07
Sign up for freeto 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.

3 participants

@pelikhan