Skip to content

[jsweep] Clean write_large_content_to_file.cjs#43312

Merged
pelikhan merged 4 commits into
mainfrom
signed/jsweep/write-large-content-to-file-3795da24ae9284e2
Jul 4, 2026
Merged

[jsweep] Clean write_large_content_to_file.cjs#43312
pelikhan merged 4 commits into
mainfrom
signed/jsweep/write-large-content-to-file-3795da24ae9284e2

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Cleaned write_large_content_to_file.cjs as part of the daily JavaScript unbloat workflow.

Context Type

Node.js (pure Node module). The file writes content to a temp file and returns a { filename, description } metadata object.

Changes Made

Type Annotation Improvement

  • Sharpened the @returns JSDoc from the vague {Object} to the precise {{ filename: string, description: string }} so TypeScript can infer the return shape without a cast.

Test Improvements

Added 5 new test cases to write_large_content_to_file.test.cjs:

New test Rationale
JSON boolean primitive covers the boolean code path in generateCompactSchema
JSON string primitive covers the string code path
Array of primitives verifies [string] (3 items) format
Object with >10 keys verifies the truncation branch (...} (12 keys))
Exact returned keys asserts Object.keys(result) equals ["filename", "description"]

Total tests: 19 (was 14, +5 new)

Validation

All checks passed:

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js ✓ (19/19 passing)

@ts-nocheck was not present — the file already had @ts-check enabled.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • traces.example.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "traces.example.com"

See Network Configuration for more information.

Generated by 🧹 jsweep - JavaScript Unbloater · 67.3 AIC · ⌖ 11.3 AIC · ⊞ 7.4K ·

  • expires on Jul 5, 2026, 9:06 PM UTC-08:00

…file.cjs

- Sharpen @returns JSDoc from generic {Object} to typed {filename: string, description: string}
- Add 5 new test cases:
  - JSON boolean primitive
  - JSON string primitive
  - Array of primitives
  - Objects with more than 10 keys (truncation check)
  - Verify returned keys are exactly filename and description
- Total test count: 19 (was 14)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Great work from the jsweep workflow on cleaning up write_large_content_to_file.cjs! 🧹

This PR is well-structured and ready for review:

  • Focused — touches exactly one module and its test file, nothing more.
  • Well-described — the body clearly documents what changed, why each test case was added, and confirms all checks pass (format, lint, typecheck, tests: 19/19 ✅).
  • Tests included — 5 new test cases covering previously untested code paths (boolean, string primitives, array of primitives, >10-key object truncation, and exact return-key assertion).
  • No new dependencies introduced.

The JSDoc sharpening from {Object} to {{ filename: string, description: string }} is a nice quality-of-life improvement for downstream type inference. This looks ready for a maintainer to approve and merge.

Generated by ✅ Contribution Check · 104.3 AIC · ⌖ 12.5 AIC · ⊞ 6.3K ·

@pelikhan pelikhan marked this pull request as ready for review July 4, 2026 06:43
Copilot AI review requested due to automatic review settings July 4, 2026 06:43
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories.

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 performs a small cleanup of the actions/setup/js/write_large_content_to_file.cjs helper used by gh-aw’s setup scripts, improving type inference for its return value and expanding integration-style test coverage around schema description generation.

Changes:

  • Refined the @returns JSDoc type for writeLargeContentToFile() to an explicit { filename: string, description: string } shape for better TypeScript inference under // @ts-check.
  • Added 5 new tests to cover JSON primitive handling, array-of-primitives formatting, object key truncation behavior, and exact return keys.
Show a summary per file
File Description
actions/setup/js/write_large_content_to_file.cjs Tightens JSDoc return typing for improved static checking without changing runtime behavior.
actions/setup/js/write_large_content_to_file.test.cjs Adds test cases covering additional generateCompactSchema branches as exercised via writeLargeContentToFile.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clean, low-risk cleanup. The JSDoc sharpening is correct and the 5 new test cases properly exercise the previously untested code paths in generateCompactSchema. All assertions verified against the implementation — no issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 17.9 AIC · ⌖ 8.2 AIC · ⊞ 4.9K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /tdd — 2 minor suggestions on assertion robustness; no blocking issues.

📋 Key Themes & Highlights

Key Themes

  • Regex over-matching (line 209): The truncation test uses .* which is too permissive — a literal toBe(...) would pin the actual key list.
  • Key order coupling (line 218): The return-shape test uses toEqual(["filename", "description"]) which is order-sensitive; prefer a length-check + presence-check pattern.

Positive Highlights

  • ✅ Great coverage of all primitive code paths (boolean, string) that were previously untested
  • ✅ Array-of-primitives test correctly validates the [string] (3 items) format
  • ✅ JSDoc @returns sharpened from {Object} to {{ filename: string, description: string }} — a real type-narrowing improvement
  • ✅ Test file structure is consistent with existing patterns (async import, beforeEach/afterEach cleanup)
  • ✅ 19/19 tests passing — no regressions

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 45.2 AIC · ⌖ 5.37 AIC · ⊞ 6.6K
Comment /matt to run again

const content = JSON.stringify(obj);
const result = writeLargeContentToFile(content);

expect(result.description).toMatch(/^\{key0, key1, key2,.*\.\.\.\} \(12 keys\)$/);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] The .* wildcard lets this assertion pass even if key3–key9 are garbled or missing — tighten to a literal match to actually pin the implementation.

💡 Suggested assertion
expect(result.description).toBe(
  "{key0, key1, key2, key3, key4, key5, key6, key7, key8, key9, ...} (12 keys)"
);

A literal toBe(...) pins the full truncated key list; the current regex would pass even if middle keys were reordered or omitted.

@copilot please address this.

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.

Addressed in 4638dca by replacing the permissive truncation regex with an exact toBe(...) assertion in actions/setup/js/write_large_content_to_file.test.cjs.

const content = JSON.stringify({ a: 1 });
const result = writeLargeContentToFile(content);

expect(Object.keys(result)).toEqual(["filename", "description"]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] Object.keys() order is not guaranteed by spec for all JS engines, though V8 preserves insertion order for string keys. Using toEqual(["filename", "description"]) will silently fail if the return object is ever reordered.

💡 More resilient alternatives

Either assert key presence without order concern:

expect(result).toHaveProperty("filename");
expect(result).toHaveProperty("description");
expect(Object.keys(result)).toHaveLength(2);

Or use toContain for each expected key:

expect(Object.keys(result)).toContain("filename");
expect(Object.keys(result)).toContain("description");

The existing toHaveProperty tests in earlier cases already cover presence; this test is most valuable for asserting no extra keys are returned.

@copilot please address this.

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.

Addressed in 4638dca by replacing the order-sensitive keys assertion with presence + length checks in actions/setup/js/write_large_content_to_file.test.cjs.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 73/100 — Acceptable

Analyzed 19 test(s): 18 design, 1 implementation, 0 violation(s).

📊 Metrics (19 tests)
Metric Value
Analyzed 19 (Go: 0, JS: 19)
✅ Design 18 (94.7%)
⚠️ Implementation 1 (5.3%)
Edge/error coverage 13 (68.4%)
Duplicate clusters 1
Inflation ⚠️ Yes (46 test lines : 1 prod line — greenfield test suite for existing function)
🚨 Violations 0
Test File Classification Issues
should create directory if it doesn't exist write_large_content_to_file.test.cjs design_test
should write content to file with hash-based filename write_large_content_to_file.test.cjs design_test
should return schema description write_large_content_to_file.test.cjs design_test
should use .json extension write_large_content_to_file.test.cjs implementation_test Assertion fully covered by second test
should generate consistent hash for same content write_large_content_to_file.test.cjs design_test
should generate different hash for different content write_large_content_to_file.test.cjs design_test
should handle arrays write_large_content_to_file.test.cjs design_test
should handle large content write_large_content_to_file.test.cjs design_test
should handle non-JSON content gracefully write_large_content_to_file.test.cjs design_test edge case
should handle empty object write_large_content_to_file.test.cjs design_test edge case
should handle empty array write_large_content_to_file.test.cjs design_test edge case
should handle nested object (only top-level keys listed) write_large_content_to_file.test.cjs design_test
should work when directory already exists write_large_content_to_file.test.cjs design_test edge case
should handle JSON primitive (number) write_large_content_to_file.test.cjs design_test similar to boolean/string tests
should handle JSON boolean primitive write_large_content_to_file.test.cjs design_test similar to number/string tests
should handle JSON string primitive write_large_content_to_file.test.cjs design_test similar to number/boolean tests
should handle array of primitives write_large_content_to_file.test.cjs design_test
should truncate description for objects with more than 10 keys write_large_content_to_file.test.cjs design_test edge case
should return both filename and description fields write_large_content_to_file.test.cjs design_test
⚠️ Flagged Tests (2)

should use .json extension (write_large_content_to_file.test.cjs) — implementation_test. The single assertion expect(result.filename).toMatch(/\.json$/) is a strict subset of what should write content to file with hash-based filename already asserts (/^[a-f0-9]{64}\.json$/). No additional regression value; consider removing or merging.

should handle JSON primitive (number/boolean/string) (tests 14–16) — Minor duplicate cluster: all three tests share the identical pattern of passing a primitive JSON value and asserting the description equals the type name. Could be collapsed into a single table-driven loop.

Verdict

Passed. 5.3% implementation tests (threshold: 30%). No guideline violations. Score 73/100 — the inflation flag reflects a greenfield test suite added for an existing function, not harmful bloat.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🧪 Test quality analysis by Test Quality Sentinel · 58.4 AIC · ⌖ 12.7 AIC · ⊞ 6.8K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 73/100. 5.3% implementation tests (threshold: 30%). No violations detected.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Non-blocking observations only — not blocking merge

The JSDoc tightening is correct and the five new test cases cover real untested code paths. Two non-blocking issues found:

### Findings (2 medium/low, no blockers)
  1. null primitive gap (medium)generateCompactSchema returns "object" for JSON.parse("null") because typeof null === "object" in JavaScript. The new primitive tests cover boolean, string, and array but skip null, leaving this pre-existing bug unexposed. A one-liner guard in generate_compact_schema.cjs fixes it; a test here would catch it.

  2. Brittle key-order assertion (low)Object.keys(result).toEqual(["filename", "description"]) relies on V8 insertion order, which is reliable in practice but encodes an implementation detail rather than a contract. A length+membership pattern is more robust.

No correctness regressions, no logic errors, no security concerns in the diff.

🔎 Code quality review by PR Code Quality Reviewer · 195.4 AIC · ⌖ 10.7 AIC · ⊞ 5.4K
Comment /review to run again

expect(result.description).toBe("number");
});

it("should handle JSON boolean primitive", async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Missing null primitive coverage: the PR adds boolean/string/array primitive tests but omits null, which has a latent bug — typeof null === "object" in generateCompactSchema causes it to hit the object branch but then fall through to return ${typeof parsed}`` returning "object" instead of `"null"`.

💡 Why this matters and suggested fix

JSON.stringify(null) produces the valid JSON string "null". When passed to writeLargeContentToFile, generateCompactSchema parses it, gets JS null, and evaluates typeof parsed === 'object' && parsed !== null — the guard evaluates to false (because null !== null is false), so it falls through to return ${typeof parsed}``, which returns "object" (since `typeof null === 'object'` in JavaScript). A consumer reading the description would incorrectly infer the payload was an object.

Adding this test exposes the bug today:

it('should handle JSON null primitive', async () => {
  const { writeLargeContentToFile } = await import('./write_large_content_to_file.cjs');
  const content = JSON.stringify(null); // → 'null'
  const result = writeLargeContentToFile(content);
  expect(result.description).toBe('null'); // fails: returns 'object'
});

Fix in generate_compact_schema.cjs, before the object branch:

if (parsed === null) return 'null';

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.

Addressed in 4638dca: added null handling in actions/setup/js/generate_compact_schema.cjs and added a JSON null primitive test in actions/setup/js/write_large_content_to_file.test.cjs.


expect(Object.keys(result)).toEqual(["filename", "description"]);
});
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Brittle key-order assertion: expect(Object.keys(result)).toEqual(["filename", "description"]) asserts both presence and insertion order — the test is fragile if the return object is ever restructured or properties are added.

💡 Suggested fix

Use a set-membership check instead:

expect(new Set(Object.keys(result))).toEqual(new Set(['filename', 'description']));
// or
expect(result).toHaveProperty('filename');
expect(result).toHaveProperty('description');
expect(Object.keys(result)).toHaveLength(2);

The intent — verify exactly these two keys and no others — is better expressed through the length + membership pattern. V8 preserves integer-indexed then string-insertion order today, but this is an implementation detail rather than a contract.

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.

Addressed in 4638dca by changing this to toHaveProperty checks plus Object.keys(result).toHaveLength(2) in actions/setup/js/write_large_content_to_file.test.cjs.

@pelikhan

pelikhan commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

@copilot merge main and run pr-finisher skill

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, merge the latest main branch if needed, address the unresolved review feedback below, and rerun checks.

Unresolved review feedback to address (newest first):

Generated by 👨‍🍳 PR Sous Chef · 9.57 AIC · ⌖ 4.37 AIC · ⊞ 3.4K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 4, 2026 07:18
…arge-content-to-file-3795da24ae9284e2

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main and run pr-finisher skill

Done in 4638dca: merged main, ran the pr-finisher flow, addressed the in-scope review feedback, and revalidated locally (make fmt, make lint, make test-unit, make test, make recompile) plus parallel validation.

@pelikhan

pelikhan commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

@copilot please run the pr-finisher skill, merge the latest main branch if needed, address the unresolved review feedback below, and rerun checks.

Unresolved review feedback to address (newest firs...

Done in bb9a027 (with prior feedback fixes in 4638dca): synced with latest main (already up to date), replied on all referenced review threads, reran checks locally (make fmt, make lint, make test-unit, make test, make recompile), and fixed the CI mismatch by updating generate_compact_schema.test.cjs to expect "null".

Copilot AI commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

@copilot fix https://github.com/github/gh-aw/actions/runs/28699160313/job/85114725693

Addressed by bb9a027.

That failed job ran on 4638dca and failed on generate_compact_schema.test.cjs expecting "object" for null. In bb9a027 the assertion was corrected to expect "null". I also re-ran the targeted test (generate_compact_schema.test.cjs) and repo lint/test locally, and they pass.

@pelikhan pelikhan merged commit 2b9a2f3 into main Jul 4, 2026
15 checks passed
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.

4 participants