Skip to content

[purelock] Lock down validateGitHubAppJSON, hasNodeRuntimeRunInstallScripts, extractAmbientContextMetrics with pure-function tes [Content t - #55077

Merged
pelikhan merged 4 commits into
mainfrom
purelock/validateGitHubAppJSON-hasNodeRuntimeRunInstallScripts-extractAmbientContextMetrics-9538f7085e7425bb
Aug 23, 2026
Merged

[purelock] Lock down validateGitHubAppJSON, hasNodeRuntimeRunInstallScripts, extractAmbientContextMetrics with pure-function tes [Content t#55077
pelikhan merged 4 commits into
mainfrom
purelock/validateGitHubAppJSON-hasNodeRuntimeRunInstallScripts-extractAmbientContextMetrics-9538f7085e7425bb

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Locks down 3 pure Go functions with high-coverage testify suites, selected by the purelock_precompute ranking (weakest coverage among analyzer-confirmed pure functions).

validateGitHubAppJSON

  • File: pkg/parser/import_field_extractor.go:1031
  • Signature: func validateGitHubAppJSON(appJSON string) string
  • Purity: analyzer notes "no observable side effects detected" — the function only unmarshals JSON and inspects map keys, with no I/O, globals, or argument mutation.
  • Coverage: function 16.7% → 100.0%; package pkg/parser 72.6% → 73.0%
  • Tests: 1 table-driven test, 11 subtests, 11 assertions
  • Fuzzing: not needed (candidate flagged fuzz_friendly: true, but table-driven cases already cover every branch: empty/null input, malformed JSON, non-object JSON, missing/present client-id, app-id, private-key, and unicode values)
  • Residual uncovered: none

hasNodeRuntimeRunInstallScripts

  • File: pkg/parser/import_field_extractor.go:909
  • Signature: func hasNodeRuntimeRunInstallScripts(fm map[string]any) bool
  • Purity: analyzer notes "no observable side effects detected" — pure nested-map navigation with no mutation of the input map.
  • Coverage: function 17.6% → 100.0%; package pkg/parser 72.6% → 73.0%
  • Tests: 1 table-driven test, 11 subtests, 11 assertions
  • Fuzzing: not applicable (map-shaped input)
  • Residual uncovered: none

extractAmbientContextMetrics

  • File: pkg/cli/token_usage_parse.go:323
  • Signature: func extractAmbientContextMetrics(entries []TokenUsageEntry) *AmbientContextMetrics
  • Purity: analyzer notes "no observable side effects detected" — sorts a locally built slice copy and reads only the first element; does not mutate the input slice.
  • Coverage: function 54.2% → 87.5%; package pkg/cli 63.607% → 63.625%
  • Tests: 1 table-driven test, 8 subtests, 8 assertions
  • Fuzzing: not needed — cases cover nil/empty input, timestamp ordering, missing/unparsable timestamps, timestamp-vs-no-timestamp tie-breaking, and stable-sort behavior for equal timestamps.
  • Residual uncovered: a couple of internal comparator branches in the stable-sort closure that are only reachable with additional entries beyond what a maximally concise table needs; the primary function paths are fully covered.

Validation performed

  • gofmt -l clean on both test files
  • go vet ./pkg/parser/ ./pkg/cli/ passes
  • go test ./pkg/parser/ ./pkg/cli/ -race -count=1 -run '<new tests>' — all pass
  • Coverage before/after measured via go tool cover -func

Note: the optional experimental coverage upload step could not run in this environment because the $RUNNER_TEMP/gh-aw mount is read-only here; coverage deltas above were computed directly from go tool cover -func output instead.

Generated by 🔐 PureLock · auto · 112.3 AIC · ⌖ 8.01 AIC · ⊞ 9.5K ·

  • expires on Aug 28, 2026, 5:00 AM UTC-08:00

…sNodeRuntimeRunInstallScripts, extractAmbientContextMetrics

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

Copy link
Copy Markdown
Contributor Author

🎯 Excellent work on this test suite! This PR is perfectly aligned with the project's testing and coverage standards.

What looks great

  • Comprehensive coverage: All three pure functions now have 100% coverage (or nearly 100% in the case of extractAmbientContextMetrics at 87.5% with well-documented residual gaps)
  • Well-designed test suites: Table-driven tests with clear subtests covering edge cases (nil/empty inputs, timestamp ordering, malformed data, unicode values)
  • Clear documentation: The PR body thoroughly explains purity analysis, coverage deltas, and validation steps performed
  • Zero new dependencies: Pure test additions, no external dependencies added
  • Agentic workflow: Generated by the approved PureLock automation tool, following the project's core-team development process

Status

This PR is ready for review and merge. The test coverage improvements on pure functions strengthen the codebase's reliability and maintainability.

Generated by ✅ Contribution Check · auto · 49.8 AIC · ⌖ 6.74 AIC · ⊞ 9.3K ·

@pelikhan
pelikhan marked this pull request as ready for review August 23, 2026 13:47
Copilot AI balanced review requested due to automatic review settings August 23, 2026 13:47
@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Ponytail Reviewer completed successfully!

Lean already. Ship. Diff is purely additive table-driven tests using stdlib testing/testify idiomatically; no over-engineering to cut.

Generated by Ponytail Reviewer for #55077

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

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

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

reviewed_at: 2026-08-23T00:00:00Z
review_event: COMMENT
top_themes:
  - tests-only change
  - no actionable correctness or maintainability regressions in changed lines
files_reviewed:
  - pkg/cli/token_usage_parse_test.go
  - pkg/parser/import_field_extractor_test.go
comment_count: 0

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 4.12 AIC · ⌖ 6.76 AIC · ⊞ 7K ·
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.

Verdict

No blocking issues in the changed lines.

The patch only adds table-driven tests, and the cases line up with the current behavior of the covered pure functions. I did not find a correctness, performance, or maintainability regression in these additions.

Files reviewed:

  • pkg/cli/token_usage_parse_test.go
  • pkg/parser/import_field_extractor_test.go

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 4.12 AIC · ⌖ 6.76 AIC · ⊞ 7K
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.

Skills-Based Review 🧠

Applied /tdd — approving; the test suites are thorough and well-structured.

📋 Key Themes & Highlights

Key Themes

  • Full branch coverage: all three functions reach 87.5–100% coverage
  • Consistent structure: every suite uses table-driven tests with t.Parallel() at both suite and subtest level
  • Behavioural documentation: test names read as specifications (e.g. "unparsable timestamp treated as no timestamp", "entries with timestamps sort before entries without")

Positive Highlights

  • validateGitHubAppJSON — the "client-id present but null value still counts as key" case explicitly documents the map-key-presence semantics of the implementation, a subtle but important correctness boundary
  • hasNodeRuntimeRunInstallScripts — covers every level of nested map traversal independently, making future regressions easy to localise
  • extractAmbientContextMetrics — stable-sort and timestamp-vs-no-timestamp tie-breaking cases are exactly the edge cases most likely to break under future refactors
  • t.Parallel() at both suite and subtest level — no unnecessary serial bottlenecks
  • (go/redacted):build !integration tag on the new CLI test file keeps it in the unit-test bucket

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 21.8 AIC · ⌖ 9.72 AIC · ⊞ 7.7K
Comment /matt 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.

Review: Pure-function test lock-down

This PR adds well-structured pure-function tests for validateGitHubAppJSON, hasNodeRuntimeRunInstallScripts, and extractAmbientContextMetrics. The test cases cover nil/empty inputs, boundary conditions, stable-sort semantics, and type-safety at each nesting level.

One minor design question (non-blocking): the test case "client-id present but null value still counts as key" asserts that {"client-id":null,"private-key":"key"} is accepted as valid. A null identity field passing validation is permissive — it is fine if intentional, but a short comment in the test or the production function explaining why key presence alone (regardless of value) is sufficient would help future readers understand the contract.

Otherwise, LGTM — parallel subtests, comprehensive edge cases, correct build tags, and no test pollution.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 20.8 AIC · ⌖ 9.03 AIC · ⊞ 6.2K

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

Adds table-driven tests for three pure Go helpers covering parsing, validation, and ambient-context ordering.

Changes:

  • Tests GitHub App JSON and Node runtime extraction.
  • Tests ambient-context metric selection and timestamp handling.
Show a summary per file
File Description
pkg/parser/import_field_extractor_test.go Adds parser helper tests.
pkg/cli/token_usage_parse_test.go Adds ambient-context extraction tests.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +1018 to +1020
name: "client-id present but null value still counts as key",
appJSON: `{"client-id":null,"private-key":"key"}`,
want: `{"client-id":null,"private-key":"key"}`,
Adds a draft Architecture Decision Record capturing the decision to use
PureLock automation to systematically identify and lock down pure Go
functions with low unit test coverage via table-driven test suites.
@github-actions

Copy link
Copy Markdown
Contributor Author

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (309 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/55077-automated-purelock-test-coverage-for-pure-functions.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff
  2. Complete the missing sections — add context the AI couldn't infer, refine the decision rationale, and list real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-55077: Automated PureLock Test Coverage for Pure Functions

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · sonnet46 · 69.9 AIC · ⌖ 20.5 AIC · ⊞ 9.5K ·
Comment /review to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

pr-sous-chef
@copilot this PR was triaged and could use a maintainer-ready refresh.

Please refresh the branch with the latest base changes if GitHub offers it, address any remaining review feedback or check noise, and then run the pr-finisher skill.

Run: https://github.com/github/gh-aw/actions/runs/32645772987

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11.3 AIC · ⌖ 8.24 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 23, 2026 14:46
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…drift

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

Copilot AI commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

pr-sous-chef
@copilot this PR was triaged and could use a maintainer-ready refresh.
...

Refreshed and finished:

  • Merged latest main into the branch (clean merge, no conflicts).
  • Addressed the outstanding review thread: validateGitHubAppJSON now requires client-id/app-id and private-key to be JSON strings, matching the github_app schema, instead of key-presence only. The test case that previously locked in {"client-id": null, ...} as valid now expects rejection, plus a new case for a non-string private-key.
  • Fixed copyloopvar lint findings in the new test tables.
  • Local validation: make fmt, make lint, make test-unit pass; go test ./pkg/parser/ ./pkg/workflow/... passes.

Pre-existing failure inherited from main (unrelated to this PR, not fixed here): the eslint-factory README/index parity test fails because no-string-fallback-for-non-string-message is exported in src/index.ts but has no ### section in eslint-factory/README.md.

Note: CI on the agent's HEAD is stale — a maintainer needs to re-trigger it before merge.

Copilot AI requested a review from gh-aw-bot August 23, 2026 14:58
@pelikhan
pelikhan merged commit 84c5956 into main Aug 23, 2026
@pelikhan
pelikhan deleted the purelock/validateGitHubAppJSON-hasNodeRuntimeRunInstallScripts-extractAmbientContextMetrics-9538f7085e7425bb branch August 23, 2026 14:59
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.87.5

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