Skip to content

[purelock] Lock down recommendAuditComparisonAction, prepareNestedMapValueForYAML, gatewayEntryToTimelineEvent with pure-functio [Content truncated due to length] - #53123

Merged
pelikhan merged 2 commits into
mainfrom
purelock/lock-audit-yaml-gateway-funcs-ffaae23efcdde45e
Aug 16, 2026
Merged

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds testify table-driven test suites for three low-coverage pure Go functions — recommendAuditComparisonAction, gatewayEntryToTimelineEvent, and prepareNestedMapValueForYAML — and records the automation rationale in a draft ADR. No production code was changed; this is a test-coverage-only PR generated by PureLock.

Change Classification

  • Type: test
  • Scope: pkg/cli, pkg/workflow, docs/adr
  • Breaking: No

Key Changes

File Change Impact
pkg/cli/audit_comparison_test.go Added table-driven tests for recommendAuditComparisonAction covering priority ordering, conclusion types, deltas, and fallback logic High
pkg/cli/gateway_logs_timeline_test.go Added table-driven tests for gatewayEntryToTimelineEvent covering timestamp parsing, type-specific field handling (DIFC_FILTERED, GUARD_POLICY_BLOCKED, tool_call, rpc_call, request), and fallback logic High
pkg/workflow/yaml_test.go Added table-driven tests for prepareNestedMapValueForYAML covering map key ordering, nested yaml.MapSlice handling, and scalar type preservation High
docs/adr/53123-purelock-automated-pure-function-test-coverage.md Added draft ADR documenting the PureLock automated coverage-generation decision Medium

Impact Assessment

  • No production code was modified; only test files and documentation.
  • Raises statement/branch coverage for three previously under-tested pure functions (46–61% baseline) to full branch coverage.
  • No API, behavior, or downstream consumer impact — tests assert existing function behavior only.

Commits

2248e0285 docs(adr): add draft ADR-53123 for PureLock automated pure-function test coverage
1a98a57de test: lock down pure functions with testify suites
```> Generated by [PR Description Updater](https://github.com/github/gh-aw/actions/runs/31950346626) for #53123 · auto · 48.2 AIC · ⌖ 3.6 AIC · ⊞ 7.5K · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw+%22gh-aw-workflow-call-id%3A+github%2Fgh-aw%2Fpr-description-caveman%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: PR Description Updater, engine: copilot, model: auto, id: 31950346626, workflow_id: pr-description-caveman, run: https://github.com/github/gh-aw/actions/runs/31950346626 -->

- recommendAuditComparisonAction (pkg/cli/audit_comparison.go): 100% coverage
- gatewayEntryToTimelineEvent (pkg/cli/gateway_logs_timeline.go): 100% coverage
- prepareNestedMapValueForYAML (pkg/workflow/yaml.go): 100% coverage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review August 16, 2026 13:01
Copilot AI balanced review requested due to automatic review settings August 16, 2026 13:01
@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

Completed PR review locally; no GitHub write was needed because I found no actionable review comments to submit.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Ponytail Reviewer completed successfully!

Ponytail review: diff is purely additive test files (table-driven tests for 3 pure functions). No hand-rolled stdlib reimplementations, no unneeded dependencies, no speculative abstractions, and no dead flexibility introduced. Lean already. Ship.

Generated by Ponytail Reviewer for #53123

@github-actions

github-actions Bot commented Aug 16, 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 16, 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

github-actions Bot commented Aug 16, 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

Copy link
Copy Markdown
Contributor Author

Comment Memory

reviewed_at: 2026-08-16T00:00:00Z
review_event: COMMENT
top_themes:
  - test-only changes
  - no actionable blocking issues found
files_reviewed:
  - pkg/cli/audit_comparison_test.go
  - pkg/cli/gateway_logs_timeline_test.go
  - pkg/workflow/yaml_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.46 AIC · ⌖ 5.42 AIC · ⊞ 6.9K ·
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.

The PR adds pure-function tests for recommendAuditComparisonAction, prepareNestedMapValueForYAML, and gatewayEntryToTimelineEvent. Tests are well-structured, use t.Parallel() where appropriate, and cover priority ordering, edge cases (empty timestamps, non-string map keys, scalar passthrough), and fallback behaviours. No production code is changed. LGTM.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 15.4 AIC · ⌖ 7.04 AIC · ⊞ 5.7K

@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 — commenting with minor observations on coverage and test hygiene.

📋 Key Themes & Highlights

Key Themes

  • t.Parallel() inconsistency: TestGatewayEntryToTimelineEvent skips parallelism used by the other two new suites.
  • Minor coverage gap: The changed+success+empty-delta combination in recommendAuditComparisonAction is not explicitly verified.
  • []any recursion assumption: A comment in the YAML test acknowledges an implicit behaviour without asserting it.

Positive Highlights

  • ✅ Excellent branch coverage across all three functions — every decision path is exercised.
  • ✅ Priority-ordering tests for recommendAuditComparisonAction are well-structured and exhaustive.
  • ServerID/ServerName fallback for both DIFC_FILTERED and GUARD_POLICY_BLOCKED is tested explicitly.
  • ✅ Scalar-passthrough and nil handling tested cleanly.
  • ✅ All test files pass gofmt and go vet per the PR description.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 29.6 AIC · ⌖ 8.69 AIC · ⊞ 7.8K
Comment /matt to run again


// ─── gatewayEntryToTimelineEvent ───────────────────────────────────────────────

func TestGatewayEntryToTimelineEvent(t *testing.T) {

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] TestGatewayEntryToTimelineEvent is missing t.Parallel() on the parent test and subtests — the other two new test functions both call it. Omitting it slows the test suite when running in parallel with other tests.

💡 Suggested fix

Add t.Parallel() immediately after t.Run(tt.name, func(t *testing.T) { for each subtest, and at the top of the parent function.

@copilot please address this.

expectedContains: "Review first-time write-capable behavior",
},
{
name: "newly present MCP failure",

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 fallback default review message subtest (line ~221) verifies that decreased blocked requests and turns fall through to the default message. But there is no test case for all delta fields being zero-valued (AuditComparisonDelta{}) with a changed label and success conclusion — it is ambiguous whether that path also lands on the fallback or takes a different route.

💡 Suggested addition
{
    name:              "empty delta with changed label falls back to default",
    label:             "changed",
    currentConclusion: "success",
    delta:             &AuditComparisonDelta{},
    expectedContains:  "Review the behavior change against the selected successful baseline",
},

@copilot please address this.

Comment thread pkg/workflow/yaml_test.go
t.Errorf("expected nested key to be preserved")
}
// original map must not be mutated by copy
if &copied == &value {

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 []any recursively processes elements subtest checks that arr[0] stays a map[string]any, but when the fieldName passed to recursion is empty (""), prepareNestedMapValueForYAML won't apply priority-field ordering. The comment inside the test acknowledges this but it would be clearer to assert that the recursive call's own fieldName is irrelevant here — or confirm whether an empty fieldName matches any priority field. If it accidentally does match, the element would be unexpectedly transformed.

💡 Suggested clarification

Either assert the exact type returned (e.g. it does NOT become a yaml.MapSlice), or add a comment citing which argument prepareNestedMapValueForYAML receives for the slice element so future readers don't have to check the implementation.

@copilot please address this.

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 targeted unit tests to lock down three pure mapping and recommendation functions.

Changes:

  • Covers audit recommendation branches and priorities.
  • Tests gateway log-to-timeline conversion.
  • Tests nested YAML ordering and copying behavior.
Show a summary per file
File Description
pkg/cli/audit_comparison_test.go Tests recommendation outcomes and priority ordering.
pkg/cli/gateway_logs_timeline_test.go Tests gateway event conversion paths.
pkg/workflow/yaml_test.go Tests nested YAML transformations.

Review details

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

Suppressed comments (2)

pkg/cli/gateway_logs_timeline_test.go:1168

  • The fixture supplies non-zero Method and Duration, but the test never asserts either output field. Removing the assignments at gateway_logs_timeline.go:183-184 would still pass this purported mapping lock-down. Assert both values in the shared successful-event checks.
			if tt.wantStatus != "" && evt.Status != tt.wantStatus {
				t.Errorf("Status = %q, want %q", evt.Status, tt.wantStatus)
			}

pkg/workflow/yaml_test.go:671

  • This case only verifies the result type, so it still passes if the map[string]string branch drops entries, values, or sorting entirely while returning any yaml.MapSlice. Assert the complete ordered contents to lock down this distinct type-switch branch.
		if _, ok := result.(yaml.MapSlice); !ok {
			t.Fatalf("expected yaml.MapSlice, got %T", result)
		}
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread pkg/workflow/yaml_test.go
Comment on lines +660 to +663
// original map must not be mutated by copy
if &copied == &value {
t.Errorf("expected a distinct copied map")
}
Comment on lines +1148 to +1150
if !tt.wantOK {
return
}
@github-actions

Copy link
Copy Markdown
Contributor Author

🏗️ Design Decision Gate — ADR Required

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

📄 Draft ADR committed: docs/adr/53123-purelock-automated-pure-function-test-coverage.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-53123: PureLock — Automated Pure-Function Test Coverage

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., 53123-purelock-automated-pure-function-test-coverage.md for PR #53123).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · sonnet46 · 69.5 AIC · ⌖ 24 AIC · ⊞ 9K ·
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

🎯 Great work on the PureLock automation! This PR looks ready for review.

What's here:
Three comprehensive test suites adding 472 lines of coverage for pure Go functions:

  • recommendAuditComparisonAction — 46.7% → 100% coverage (14 subtests)
  • prepareNestedMapValueForYAML — 60.9% → 100% coverage (10 subtests)
  • gatewayEntryToTimelineEvent — 48.5% → 100% coverage (10 subtests)

The PR aligns with the project's agentic development model, all tests are focused and well-documented, coverage improvements are significant, and validation passes (gofmt, go vet, -race flag). This is a solid contribution to test infrastructure.

Generated by ✅ Contribution Check · auto · 56.8 AIC · ⌖ 3.74 AIC · ⊞ 9.1K ·

@pelikhan
pelikhan merged commit 20e3005 into main Aug 16, 2026
4 checks passed
@pelikhan
pelikhan deleted the purelock/lock-audit-yaml-gateway-funcs-ffaae23efcdde45e branch August 16, 2026 13:37
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.87.1

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