Skip to content

[purelock] Lock down selectHistoricalOperationalValueGrader, extractHostFromRemoteURL, extractOTLPAttributesFromObsMap with pure [Content t - #56895

Merged
pelikhan merged 3 commits into
mainfrom
purelock/three-func-tests-1788008257-652a7c574d71b396
Aug 29, 2026
Merged

[purelock] Lock down selectHistoricalOperationalValueGrader, extractHostFromRemoteURL, extractOTLPAttributesFromObsMap with pure [Content t#56895
pelikhan merged 3 commits into
mainfrom
purelock/three-func-tests-1788008257-652a7c574d71b396

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

PureLock 🔐 — 3 pure functions locked down

Precomputed coverage source: func-coverage.txt (merged coverage profile + fixed-point purity analysis).

1. selectHistoricalOperationalValueGrader

  • File: pkg/cli/graders_operational_value_regrade.go:296
  • Signature: func selectHistoricalOperationalValueGrader(manifest *operationalValueGraderManifest, artifact *graderResultsArtifact, runID string) (*operationalValueGraderManifestEntry, *graderArtifactResult, error)
  • Purity: precomputed purity_notes said "no observable side effects detected." Verified by inspection: the function only reads fields off its manifest/artifact pointer arguments, performs no I/O, no goroutines, no global/package state mutation, and returns derived pointers/errors deterministically based solely on its inputs.
  • Coverage: function 0% → 100%; package pkg/cli 63.9% → 64.0%.
  • Tests: 1 top-level table-driven test, 10 subtests, ~20 assertions (error-string checks + entry/result identity checks) covering nil manifest, nil artifact, duplicate manifest entries, duplicate artifact results, missing/disabled/wrong-source manifest entry, missing/no-observation artifact result, and the success path.
  • No fuzzing needed (function operates over small structured inputs, not raw byte/string parsing). No uncovered lines remain.

2. extractHostFromRemoteURL

  • File: pkg/cli/git.go:141
  • Signature: func extractHostFromRemoteURL(remoteURL string) string
  • Purity: precomputed purity_notes said "no observable side effects detected." Verified: pure string/URL parsing via net/url.Parse and strings helpers, no I/O, no shared state, deterministic output for a given input string.
  • Coverage: function 64.0% → 96.0%; package pkg/cli 63.9% → 64.0%.
  • Tests: extended the existing TestExtractHostFromRemoteURL table with 4 new cases exercising the url.Parse failure fallback branches (malformed %zz escapes with/without userinfo and path) and the scp-like "slash before colon" guard that falls through to the github.com default.
  • fuzz_friendly was true in the candidate metadata; a dedicated fuzz test was not added since the manual fallback branches are now exercised directly by the new table cases and residual risk is low. Residual uncovered: one defensive branch inside the manual-fallback path for URLs with neither @ nor / after the scheme, considered low-value to special-case further.

3. extractOTLPAttributesFromObsMap

  • File: pkg/parser/import_observability.go:173
  • Signature: func extractOTLPAttributesFromObsMap(obs map[string]any) map[string]string
  • Purity: precomputed purity_notes said "no observable side effects detected." Verified: pure map traversal/type-assertion logic building and returning a new map, no I/O, no mutation of the input, no global state.
  • Coverage: function 42.1% → 100%; package pkg/parser 73.7% → 73.9%.
  • Tests: new file pkg/parser/import_observability_test.go with 1 table-driven test, 9 subtests, 9 assertions covering nil map, empty map, missing otlp key, non-map otlp/attributes values, empty attributes, string-valued attributes, non-string values being silently dropped (int/bool/nested map/slice/nil), and empty-key filtering.
  • No fuzzing needed; all branches of the map-traversal logic are now covered, no residual uncovered lines.

Validation performed

  • gofmt -l clean on all 3 modified/added test files.
  • go vet ./pkg/cli/ ./pkg/parser/ passes with no findings.
  • go test ./pkg/cli/ -race -count=1 and go test ./pkg/parser/ -race -count=1 both pass for the new/targeted tests (full-package runs surface a handful of pre-existing, unrelated failures caused by this sandbox's read-only /tmp filesystem and lack of outbound network/GH auth — e.g. TestValidateWithSchemaAndLocation_CleanedErrorMessage, TestBuildLogsFileResponse_*, TestInstallCopilotCLIScript* — none of which touch the 3 functions locked down here).
  • Coverage before/after captured via go tool cover -func on isolated before/after profiles per package.
  • Combined cobertura report for pkg/cli + pkg/parser generated and uploaded as purelock/generated-tests.

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com
  • raw.githubusercontent.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

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

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"
    - "raw.githubusercontent.com"

See Network Configuration for more information.

Generated by 🔐 PureLock · copilot · auto · 111.5 AIC · ⌖ 27.2 AIC · ⊞ 9.7K ·

  • expires on Sep 3, 2026, 5:02 AM UTC-08:00

…, extractHostFromRemoteURL, extractOTLPAttributesFromObsMap

- pkg/cli/graders_operational_value_regrade.go: selectHistoricalOperationalValueGrader (coverage 0% -> 100%)
- pkg/cli/git.go: extractHostFromRemoteURL (coverage 64% -> 96%)
- pkg/parser/import_observability.go: extractOTLPAttributesFromObsMap (coverage 42.1% -> 100%)

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

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

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

Copy link
Copy Markdown
Contributor Author

⚠️ Security scanning failed for Ponytail Reviewer. Review the logs for details.

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • api.github.com
  • chatgpt.com
  • github.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

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

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "api.github.com"
    - "chatgpt.com"
    - "github.com"

See Network Configuration for more information.

Generated by Ponytail Reviewer for #56895

@github-actions

github-actions Bot commented Aug 29, 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 29, 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-29T13:29:00Z
review_event: COMMENT
top_themes:
  - test-only change
  - added branch coverage for pure helpers
  - no blocking correctness issues found
files_reviewed:
  - pkg/cli/git_test.go
  - pkg/cli/graders_operational_value_regrade_test.go
  - pkg/parser/import_observability_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 · pi · gpt54 · 4.18 AIC · ⌖ 7.33 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: non-blocking

This PR only adds targeted tests, and I did not find an actionable correctness, performance, or maintainability problem in the changed lines.

Notes
  • pkg/cli/git_test.go adds coverage for malformed URL fallback branches and the scp-like non-match case.
  • pkg/cli/graders_operational_value_regrade_test.go exercises the expected nil/duplicate/mismatch error paths and the success path for the historical grader selector.
  • pkg/parser/import_observability_test.go covers absent, malformed, empty, and mixed-type observability attribute inputs.
  • The requested grumpy-coder sub-agent could not be used because the executable is unavailable in this environment, so its output was discarded.

🔎 Code quality review by PR Code Quality Reviewer · pi · gpt54 · 4.18 AIC · ⌖ 7.33 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 — no blocking issues. Three minor observations posted as inline comments.

📋 Key Themes & Highlights

Key Themes

  • nil vs empty map asymmetry (import_observability_test.go line 54): extractOTLPAttributesFromObsMap returns map[string]string{} for empty attributes but nil for all absent-key paths — worth documenting whether that distinction is intentional.
  • Hardcoded result ID (graders_operational_value_regrade_test.go line 355): success-path assertion uses a literal "operational-value" instead of a table field, reducing extensibility.
  • Undocumented fallback behaviour (git_test.go line 591): the "%zz" expected value is surprising without a comment explaining the manual-fallback logic.

Positive Highlights

  • ✅ Comprehensive table-driven tests across all 3 functions with clear names
  • ✅ Consistent t.Parallel() usage; no test-isolation issues
  • ✅ Error assertions check both the error message and that pointers are nil — good defensive style
  • import_observability_test.go uses testify/assert consistently with the rest of pkg/parser

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet46 · 25.6 AIC · ⌖ 10.7 AIC · ⊞ 7.7K
Comment /matt to run again

name: "empty attributes map returns empty result",
obs: map[string]any{"otlp": map[string]any{"attributes": map[string]any{}}},
expected: map[string]string{},
},

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 "empty attributes map" case returns map[string]string{} while all "not found" paths return nil — verify this asymmetry is intentional in the production code.

💡 Why this matters

Callers that guard with if result != nil will see a non-nil result for an empty attributes map, even though there is nothing useful in it. If the production function intends nil to mean "no OTLP config" uniformly, this test case may be revealing an inconsistency worth fixing.

Consider adding a comment in the test (or production code) explaining why empty-attributes is distinct from absent-attributes.

@copilot please address this.

if tt.wantErr != "" {
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
t.Fatalf("expected error containing %q, got %v", tt.wantErr, err)
}

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 success-path assertion hardcodes "operational-value" as the expected result.ID rather than reading it from tt — this means adding a second success case with a different ID would silently pass a wrong assertion.

💡 Suggested fix

Add a wantResultID field to the test struct (mirroring wantEntryID) and assert against it:

if result == nil || result.ID != tt.wantResultID {
    t.Fatalf("expected result with ID %q, got %v", tt.wantResultID, result)
}

For the existing success case, set wantResultID: "operational-value".

@copilot please address this.

Comment thread pkg/cli/git_test.go
},
{
name: "SSH scp-like with slash before colon does not match and defaults to github.com",
url: "some/path:notaport",

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 case "malformed URL falls back to manual parsing with no userinfo and no path" expects "%zz" as the host — this is an edge case where neither @ nor / is present after the scheme, and the test documents that the raw remainder is returned verbatim.

Consider adding a brief comment to this test case (or the production code) explaining that "%zz" is returned because the manual-fallback strips the scheme and finds no delimiter, so the residual string IS the "host". Without that comment, a future reader might assume it is a bug.

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor Author

ADR Required

This PR triggered the design decision gate because it adds more than 100 new lines in business-logic directories (pkg/cli and pkg/parser): the prefetch summary reports 244 additions.

I did not find an existing ADR in the PR body, and the latest ADR already on the branch (docs/adr/56599-add-intent-field-to-workflow-frontmatter.md) is unrelated to this change.

To keep the branch mergeable, I added a draft ADR here:

  • docs/adr/56895-add-adrs-for-pure-function-test-lockdown.md

Evidence used:

  • pr.diff shows only test additions for selectHistoricalOperationalValueGrader, extractHostFromRemoteURL, and extractOTLPAttributesFromObsMap
  • pr.json body describes the change as locking down three pure functions with targeted coverage and deterministic behavior

Next action

Please review and refine the draft ADR so the stated context, decision, trade-offs, and consequences match the intent of this PR before merge.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · gpt54 · 7.32 AIC · ⌖ 9.47 AIC · ⊞ 9.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.

Tests-only PR adding pure-lock coverage for selectHistoricalOperationalValueGrader, extractHostFromRemoteURL, and extractOTLPAttributesFromObsMap. Edge cases are well-chosen and thorough. No blocking issues.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet46 · 20.2 AIC · ⌖ 10.5 AIC · ⊞ 6.3K

@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 new coverage adds a lot of table-driven boilerplate for a tiny helper; trimming the matrix to one success case and one representative error case would preserve the signal with less test code.

net: -80 lines possible.

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • api.github.com
  • chatgpt.com
  • github.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

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

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "api.github.com"
    - "chatgpt.com"
    - "github.com"

See Network Configuration for more information.

Generated by ✂️ Ponytail Reviewer for #56895 · codex · mai10 · 7.1 AIC · ⌖ 0.64 AIC · ⊞ 13.5K
Comment /ponytail to run again

}
}

func TestSelectHistoricalOperationalValueGrader(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.

L255: shrink: 10-case table for a tiny pure helper. Keep one success case plus one representative error case.

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.

🟡 Changes recommended

Some expectations contradict documented contracts, and pointer identity remains unverified.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds targeted tests to lock down three pure parsing and selection helpers.

Changes:

  • Covers operational-value grader selection and errors.
  • Expands malformed Git remote URL cases.
  • Adds OTLP attribute extraction tests.
File summaries
File Description
pkg/cli/graders_operational_value_regrade_test.go Tests historical grader selection.
pkg/cli/git_test.go Tests remote-host parsing fallbacks.
pkg/parser/import_observability_test.go Tests OTLP attribute extraction.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Balanced

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

Comment on lines +364 to +369
if entry == nil || entry.ID != tt.wantEntryID {
t.Fatalf("expected entry with ID %q, got %v", tt.wantEntryID, entry)
}
if result == nil || result.ID != "operational-value" {
t.Fatalf("expected result with ID operational-value, got %v", result)
}
Comment on lines +51 to +53
name: "empty attributes map returns empty result",
obs: map[string]any{"otlp": map[string]any{"attributes": map[string]any{}}},
expected: map[string]string{},
Comment thread pkg/cli/git_test.go
Comment on lines +585 to +587
name: "malformed URL falls back to manual parsing with no userinfo and no path",
url: "https://%zz",
expected: "%zz",
@pelikhan

Copy link
Copy Markdown
Collaborator

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

Copilot AI commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

@copilot run pr-finisher skill
Fix https://github.com/github/gh-aw/actions/runs/33255261394/job/99107951577

Fixed in 2ee9c60.

The lint-go-golangci job was the only failing job in that run. It failed with two copyloopvar findings:

pkg/cli/graders_operational_value_regrade_test.go:348:3: The copy of the 'for' variable "tt" can be deleted (Go 1.22+)
pkg/parser/import_observability_test.go:98:3: The copy of the 'for' variable "tt" can be deleted (Go 1.22+)

Removed both redundant tt := tt statements — under Go 1.22+ loop-variable semantics each iteration already gets its own tt, so the parallel subtests still capture the correct value.

Validation: golangci-lint run on pkg/cli/... and pkg/parser/... reports 0 issues, gofmt clean, targeted tests pass, and make agent-report-progress (fmt + lint + impacted unit tests + lock-file sync) passed.

Copilot AI requested a review from pelikhan August 29, 2026 13:51
@pelikhan
pelikhan merged commit 9b3c95a into main Aug 29, 2026
32 checks passed
@pelikhan
pelikhan deleted the purelock/three-func-tests-1788008257-652a7c574d71b396 branch August 29, 2026 14:15
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.87.10

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.

3 participants