Skip to content

ci: add protected public domain allowlists - #2111

Merged
HanShaoshuai-k merged 1 commit into
mainfrom
feat/domain-allowlist
Jul 31, 2026
Merged

ci: add protected public domain allowlists#2111
HanShaoshuai-k merged 1 commit into
mainfrom
feat/domain-allowlist

Conversation

@HanShaoshuai-k

@HanShaoshuai-k HanShaoshuai-k commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a CI-enforced domain allowlist for Go source so new hostnames must be approved as public endpoints or scoped as test fixtures.

The check targets newly added code and uses hostname-aware contexts to avoid blocking unrelated dotted strings or historical code.

Changes

  • Add exact public and test-fixture domain allowlists.
  • Detect static hostnames in Host/Domain assignments and absolute URLs.
  • Validate malformed, duplicate, and unused allowlist entries in lintcheck.

Test Plan

  • Added unit and repository-level regression coverage.
  • Verified approved, rejected, fixture-only, and false-positive cases.

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added production and test-only hostname allowlists with strict ordering and validation, plus enforcement for unapproved hostname findings and unused allowlist entries.
    • Improved domain-contract linting to support incremental scanning scoped to newly changed Go lines via a base revision option.
  • Documentation

    • Updated lint domain coverage and policy guidance, including allowlist boundaries, reserved-example hostname handling, and revised --changed-from behavior.
  • Tests

    • Added unit and end-to-end coverage for allowlist validation, diff/added-line detection, hostname evidence extraction, and scan failure/incomplete handling.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds approved-domain contract linting with public and fixture allowlists, strict policy validation, incremental changed-line detection, static Go hostname scanning, violation reporting, and options-aware lint integration.

Changes

Approved Domain Contract

Layer / File(s) Summary
Domain policy and allowlists
internal/qualitygate/config/allowlists/*, internal/qualitygate/config/README.md, lint/domaincontract/policy.go, lint/domaincontract/policy_test.go
Adds public and fixture hostname lists, validates formatting and overlap rules, recognizes reserved examples, and documents policy requirements.
Incremental changed-line detection
lint/domaincontract/diff.go, lint/domaincontract/diff_test.go
Parses Git file changes and unified diff hunks to identify added Go line ranges, including rename and copy handling.
Hostname evidence scanning
lint/domaincontract/unapproved.go, lint/domaincontract/unapproved_test.go, lint/domaincontract/unapproved_repo_test.go
Detects semantic hostname values and absolute URLs, applies policy and fixture rules, and reports unapproved, unused, or incomplete scans.
Scanner orchestration and lint wiring
lint/domaincontract/scan.go, lint/main.go, lint/README.md
Adds options-aware scanning, combines deterministic violation results, passes --changed-from, and updates lint documentation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant lintcheck
  participant ScanRepoWithOptions
  participant scanHardcodedEndpoints
  participant scanUnapprovedDomains
  participant Git
  lintcheck->>ScanRepoWithOptions: ScanRepoWithOptions(root, ChangedFrom)
  ScanRepoWithOptions->>scanHardcodedEndpoints: Scan endpoint violations
  ScanRepoWithOptions->>scanUnapprovedDomains: Scan domain violations
  scanUnapprovedDomains->>Git: Read tracked files and added ranges
  scanUnapprovedDomains-->>ScanRepoWithOptions: Return domain violations
  scanHardcodedEndpoints-->>ScanRepoWithOptions: Return endpoint violations
  ScanRepoWithOptions-->>lintcheck: Return sorted combined violations
Loading

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change by calling out the new public domain allowlists, though it omits the fixture allowlist and enforcement logic.
Description check ✅ Passed The description follows the template and covers summary, changes, test plan, and related issues with the core scope described.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/domain-allowlist

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (7)
lint/domaincontract/unapproved.go (2)

337-361: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant ast.Expr assertions. composite.Elts and pair.Key are already ast.Expr; the assertions at Lines 341 and 351 always succeed and just add nesting.

♻️ Simplification
 		case sequenceComposite:
 			for _, element := range composite.Elts {
-				if valueExpr, ok := element.(ast.Expr); ok {
-					s.addHostValue(valueExpr, "host collection")
-				}
+				s.addHostValue(element, "host collection")
 			}
 		case mapComposite:
 			for _, element := range composite.Elts {
 				pair, ok := element.(*ast.KeyValueExpr)
 				if !ok {
 					continue
 				}
-				keyExpr, ok := pair.Key.(ast.Expr)
-				if !ok {
-					continue
-				}
-				s.addMapPair(keyExpr, pair.Value)
+				s.addMapPair(pair.Key, pair.Value)
 			}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/unapproved.go` around lines 337 - 361, Remove the
redundant ast.Expr type assertions in the composite literal handling: pass each
composite.Elts element directly to addHostValue, and pass pair.Key directly to
addMapPair after validating the KeyValueExpr. Keep the existing sequence/map
branching and non-KeyValueExpr skip behavior unchanged.

97-97: 🩺 Stability & Availability | 🔵 Trivial | 🏗️ Heavy lift

loadTypedGoFiles failures silently weaken the gate. packages.Load errors (and per-package pkg.Errors) are swallowed into a nil map, and any path-normalization mismatch between filepath.Clean(pkg.CompiledGoFiles[i]) and the scanned path (e.g. symlinked TMPDIR on macOS, /var vs /private/var) drops typed info for that file. Without Info, isHostnameStructField/isHostnameSelector return false by design (Lines 587-593), so struct-field and selector hostname evidence disappears while the scan still reports success and the unused-entry pass still runs repo-wide. That turns an environment problem into a false-negative CI pass.

Consider surfacing typed-load failure as inventoryComplete = false plus an incompleteDomainRule violation (or returning the error), rather than degrading quietly.

As per coding guidelines: "never silently coerce unsupported inputs, ignore unhonored options, default missing identities, or discard writes."

Also applies to: 208-244

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/unapproved.go` at line 97, Update loadTypedGoFiles and
its callers to surface packages.Load or per-package pkg.Errors instead of
returning a nil or partial typed-file map silently. Propagate an incomplete
result through the scan by setting inventoryComplete to false and recording an
incompleteDomainRule violation (or returning the load error), while preserving
existing typed evidence when loading succeeds; also normalize scanned and
compiled paths consistently so symlinked or equivalent paths still match.

Source: Coding guidelines

lint/domaincontract/policy_test.go (1)

28-95: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering the remaining loadDomainList rejection paths. "domain list must not be empty" (comment-only/blank file) and the missing-file/open-error branch (policy.go Lines 71-74, 100-102) have no test, so removing either guard wouldn't fail this suite.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/policy_test.go` around lines 28 - 95, Extend
TestLoadDomainPolicyRejectsInvalidLists with cases for a comment-only or blank
domain list, asserting the “domain list must not be empty” error, and for a
missing/unopenable domain-list file, asserting the open-error path. Use the
existing temporary-root setup and loadDomainPolicy flow while preserving all
current rejection cases.
lint/domaincontract/unapproved_test.go (1)

15-65: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicated helper bodies. scanDomainEvidence and scanTypedDomainEvidenceInPackage repeat identical parse + collect + sort logic; extracting a sortDomainEvidence helper (and a shared parse step) would keep them in sync.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/unapproved_test.go` around lines 15 - 65, Refactor
scanDomainEvidence and scanTypedDomainEvidenceInPackage to share the duplicated
parse, evidence collection, and sorting logic. Extract a sortDomainEvidence
helper and a shared parsing/scanning helper where appropriate, while preserving
the existing typed-package setup and error handling behavior.
lint/domaincontract/unapproved_repo_test.go (1)

15-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the fixture repo hermetic against ambient Git config. Repo-level user.name/user.email and -c commit.gpgsign=false are set, but a developer's global core.hooksPath, init.templateDir, or commit.gpgsign can still make init/commit fail or mutate the fixture. Pinning the environment keeps these tests deterministic on contributor machines.

♻️ Suggested isolation
 func gitTestCommand(t *testing.T, root string, args ...string) string {
 	t.Helper()
 	cmd := exec.Command("git", args...)
 	cmd.Dir = root
+	cmd.Env = append(os.Environ(),
+		"GIT_CONFIG_GLOBAL=/dev/null",
+		"GIT_CONFIG_SYSTEM=/dev/null",
+		"GIT_CONFIG_NOSYSTEM=1",
+	)
 	out, err := cmd.CombinedOutput()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/unapproved_repo_test.go` around lines 15 - 42, Update
setupDomainDiffRepo and its gitTestCommand invocations to isolate Git from
ambient configuration: disable or override global core.hooksPath and
init.templateDir during repository initialization, and explicitly disable commit
signing for the commit operation. Keep the fixture’s existing repository-local
identity configuration and ensure initialization and commit cannot execute
contributor-provided hooks or templates.
lint/domaincontract/policy.go (2)

106-126: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

IDN hostnames can never be approved. validatePolicyHostname only accepts a-z0-9- labels, so an allowlist entry must be punycode, while the scanner's normalizeCandidateHostname (unapproved.go Line 517) emits the literal Unicode host. A Unicode hostname in Go source is therefore permanently unapprovable even with CODEOWNER sign-off — there is no escape hatch. If that's the intent (as TestUnapprovedDomainDiffContract/IDN hostname is rejected suggests), consider stating it explicitly in internal/qualitygate/config/README.md; otherwise normalize candidates to A-labels (golang.org/x/net/idna) before policy lookup.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/policy.go` around lines 106 - 126, Align policy
validation with candidate normalization so IDN hostnames can be approved: update
the hostname normalization or policy lookup flow around validatePolicyHostname
and normalizeCandidateHostname to convert Unicode hostnames to IDNA A-labels
using the existing golang.org/x/net/idna dependency before comparison. Preserve
current validation for ASCII hostnames and ensure both allowlist entries and
scanner candidates use the same canonical form.

91-93: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Sort check depends on byte order, which is only safe because validatePolicyHostname restricts to ASCII. Worth a short comment tying the two invariants together so a future relaxation of the charset doesn't silently break ordering validation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/policy.go` around lines 91 - 93, Add a concise comment at
the ordering check in the policy validation flow, near validatePolicyHostname
and the previous/host comparison, documenting that byte-order sorting is valid
because hostnames are restricted to ASCII; note that relaxing the charset
requires revisiting this comparison.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lint/domaincontract/diff.go`:
- Around line 79-142: Establish the typed-error contract across the diff flow:
in lint/domaincontract/diff.go lines 79-142, make parseChangedGoPaths and
parseAddedLineRanges return typed validation errors with the required metadata;
in lint/domaincontract/diff.go lines 157-170, wrap Git subprocess failures in
the prescribed lower-layer typed error while preserving the cause. Update
lint/domaincontract/diff_test.go lines 29-33 to assert typed metadata for
truncated rename input, and lines 64-68 to assert typed metadata plus
errors.Is-style cause preservation for malformed patch data.

In `@lint/README.md`:
- Around line 33-38: Update the “Adding a new lint domain” example to avoid
assigning an options-incompatible <domain>.ScanRepo directly to scanner.fn.
Document using an options-aware scanner entry point such as ScanRepoWithOptions,
or an adapter that accepts and forwards opts while preserving the existing
scanning behavior.

---

Nitpick comments:
In `@lint/domaincontract/policy_test.go`:
- Around line 28-95: Extend TestLoadDomainPolicyRejectsInvalidLists with cases
for a comment-only or blank domain list, asserting the “domain list must not be
empty” error, and for a missing/unopenable domain-list file, asserting the
open-error path. Use the existing temporary-root setup and loadDomainPolicy flow
while preserving all current rejection cases.

In `@lint/domaincontract/policy.go`:
- Around line 106-126: Align policy validation with candidate normalization so
IDN hostnames can be approved: update the hostname normalization or policy
lookup flow around validatePolicyHostname and normalizeCandidateHostname to
convert Unicode hostnames to IDNA A-labels using the existing
golang.org/x/net/idna dependency before comparison. Preserve current validation
for ASCII hostnames and ensure both allowlist entries and scanner candidates use
the same canonical form.
- Around line 91-93: Add a concise comment at the ordering check in the policy
validation flow, near validatePolicyHostname and the previous/host comparison,
documenting that byte-order sorting is valid because hostnames are restricted to
ASCII; note that relaxing the charset requires revisiting this comparison.

In `@lint/domaincontract/unapproved_repo_test.go`:
- Around line 15-42: Update setupDomainDiffRepo and its gitTestCommand
invocations to isolate Git from ambient configuration: disable or override
global core.hooksPath and init.templateDir during repository initialization, and
explicitly disable commit signing for the commit operation. Keep the fixture’s
existing repository-local identity configuration and ensure initialization and
commit cannot execute contributor-provided hooks or templates.

In `@lint/domaincontract/unapproved_test.go`:
- Around line 15-65: Refactor scanDomainEvidence and
scanTypedDomainEvidenceInPackage to share the duplicated parse, evidence
collection, and sorting logic. Extract a sortDomainEvidence helper and a shared
parsing/scanning helper where appropriate, while preserving the existing
typed-package setup and error handling behavior.

In `@lint/domaincontract/unapproved.go`:
- Around line 337-361: Remove the redundant ast.Expr type assertions in the
composite literal handling: pass each composite.Elts element directly to
addHostValue, and pass pair.Key directly to addMapPair after validating the
KeyValueExpr. Keep the existing sequence/map branching and non-KeyValueExpr skip
behavior unchanged.
- Line 97: Update loadTypedGoFiles and its callers to surface packages.Load or
per-package pkg.Errors instead of returning a nil or partial typed-file map
silently. Propagate an incomplete result through the scan by setting
inventoryComplete to false and recording an incompleteDomainRule violation (or
returning the load error), while preserving existing typed evidence when loading
succeeds; also normalize scanned and compiled paths consistently so symlinked or
equivalent paths still match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f46ef56-94a5-4b8f-896a-2f72e5075e71

📥 Commits

Reviewing files that changed from the base of the PR and between 1f565a2 and 8fc138f.

📒 Files selected for processing (13)
  • internal/qualitygate/config/README.md
  • internal/qualitygate/config/allowlists/fixture-domains.txt
  • internal/qualitygate/config/allowlists/public-domains.txt
  • lint/README.md
  • lint/domaincontract/diff.go
  • lint/domaincontract/diff_test.go
  • lint/domaincontract/policy.go
  • lint/domaincontract/policy_test.go
  • lint/domaincontract/scan.go
  • lint/domaincontract/unapproved.go
  • lint/domaincontract/unapproved_repo_test.go
  • lint/domaincontract/unapproved_test.go
  • lint/main.go

Comment thread lint/domaincontract/diff.go
Comment thread lint/README.md
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@b1fcb46c3adacca0d43a397c7b9678485d1c7047

🧩 Skill update

npx skills add larksuite/cli#feat/domain-allowlist -y -g

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.25%. Comparing base (87be09e) to head (b1fcb46).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2111   +/-   ##
=======================================
  Coverage   75.25%   75.25%           
=======================================
  Files         916      916           
  Lines       97167    97167           
=======================================
  Hits        73121    73121           
  Misses      18433    18433           
  Partials     5613     5613           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HanShaoshuai-k
HanShaoshuai-k force-pushed the feat/domain-allowlist branch from 8fc138f to 0419c26 Compare July 30, 2026 09:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lint/domaincontract/policy.go`:
- Around line 69-75: Update loadDomainList to read the allowlist through the
repository VFS, using vfs.Open or vfs.ReadFile instead of os.Open. Translate
scanner and underlying I/O failures through the repository’s established typed
error boundary rather than returning raw fmt.Errorf, while preserving the
existing path construction and domain-list parsing behavior.
- Around line 49-103: The policy-loading functions loadDomainPolicy and
loadDomainList must use the typed-error contract: wrap hostname, ordering,
empty-list, and cross-list duplicate failures as *errs.ValidationError; wrap
os.Open and scanner read failures as *errs.InternalError with errs.SubtypeFileIO
while preserving the underlying cause. Update policy_test.go coverage to assert
these categories with errors.As rather than matching error-message substrings,
including duplicate and file-I/O cases.

In `@lint/domaincontract/unapproved.go`:
- Around line 367-382: Update fileDomainScan.addMapPair so the both-true
keyOK/valueOK case reports both hostname evidences instead of returning; retain
the early return for both-false and the existing single-sided reporting
behavior. Add a regression test in unapproved_test.go covering a
hostname-semantic map literal with hostname-shaped key and value.
- Around line 97-105: Update loadTypedGoFiles and its caller in
scanUnapprovedDomains to propagate packages.Load failures instead of silently
returning nil. When typed loading fails, mark inventoryComplete false and emit
an incompleteDomainRule/incompleteDomainViolation diagnostic, ensuring the
unused-policy rejection pass is skipped while preserving normal typed scanning
when loading succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 392d238d-525b-4fb1-9d7a-ea55421235d9

📥 Commits

Reviewing files that changed from the base of the PR and between 8fc138f and 0419c26.

📒 Files selected for processing (13)
  • internal/qualitygate/config/README.md
  • internal/qualitygate/config/allowlists/fixture-domains.txt
  • internal/qualitygate/config/allowlists/public-domains.txt
  • lint/README.md
  • lint/domaincontract/diff.go
  • lint/domaincontract/diff_test.go
  • lint/domaincontract/policy.go
  • lint/domaincontract/policy_test.go
  • lint/domaincontract/scan.go
  • lint/domaincontract/unapproved.go
  • lint/domaincontract/unapproved_repo_test.go
  • lint/domaincontract/unapproved_test.go
  • lint/main.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/qualitygate/config/README.md
  • lint/README.md

Comment thread lint/domaincontract/policy.go
Comment thread lint/domaincontract/policy.go
Comment thread lint/domaincontract/unapproved.go Outdated
Comment thread lint/domaincontract/unapproved.go
@HanShaoshuai-k
HanShaoshuai-k force-pushed the feat/domain-allowlist branch from 0419c26 to b1fcb46 Compare July 30, 2026 11:49
@github-actions github-actions Bot added size/XL Architecture-level or global-impact change and removed size/L Large or sensitive change across domains or core paths labels Jul 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (7)
lint/domaincontract/diff.go (1)

157-171: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Git invocations have no timeout or context support. In CI a hung git (e.g. credential prompt on a bad revision) blocks the lint run indefinitely. exec.CommandContext with a bounded context would fail fast.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/diff.go` around lines 157 - 171, Update gitCommandOutput
to create a bounded context and invoke git with exec.CommandContext instead of
exec.Command. Ensure the context timeout cancels hung git processes while
preserving the existing output and stderr-wrapping behavior.
lint/domaincontract/scan.go (1)

86-90: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add doc comments to the new exported symbols. ScanOptions and ScanRepoWithOptions are exported without comments; ChangedFrom semantics (base revision, empty = full inventory) are worth stating since callers in lint/main.go depend on it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/scan.go` around lines 86 - 90, Add Go doc comments for
the exported ScanOptions type, its ChangedFrom field, and ScanRepoWithOptions.
Document that ChangedFrom identifies the base revision and an empty value
requests a full inventory, matching the behavior relied on by lint/main.go.
lint/domaincontract/policy.go (2)

58-65: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Cross-list duplicate reporting is order-dependent. Iterating fixtures (a map) makes the reported entry nondeterministic when several hostnames appear in both lists. Sorting the hosts before the check would make CI output stable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/policy.go` around lines 58 - 65, Update the cross-list
duplicate check to iterate hostnames in deterministic sorted order rather than
directly ranging over the fixtures map. Preserve the existing duplicate error
construction and return behavior, using the sorted host keys before accessing
fixtures and public.

106-126: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Policy hostnames cannot express IDN hosts that the scanner can detect.

validatePolicyHostname accepts only [a-z0-9-] labels, while normalizeCandidateHostname in lint/domaincontract/unapproved.go (Lines 711-729) accepts any unicode.IsLetter/IsDigit label. So a Unicode hostname such as 例子.公司.cn can be detected as evidence but can never be approved — the only remedy is removing the code. If that is intentional, consider documenting it; otherwise normalize both sides to punycode (or allow non-ASCII labels here).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/policy.go` around lines 106 - 126, Update
validatePolicyHostname to accept the same IDN hostname forms recognized by
normalizeCandidateHostname, while preserving hostname length, label length,
non-empty label, hyphen-boundary, and final-label validation. Normalize accepted
Unicode hostnames to punycode consistently with the scanner before comparison,
or otherwise allow valid non-ASCII letter/digit labels so detected IDN hosts can
be approved.
lint/domaincontract/unapproved_repo_test.go (1)

15-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Isolate global Git configuration in these fixtures.

git init/commit here inherit the developer's global config and templates (core.excludesFile, commit.template, core.hooksPath, init.templateDir, signing defaults), which can make these repo-level tests fail or behave differently locally. Pinning the environment makes them hermetic.

♻️ Suggested isolation
 func setupDomainDiffRepo(t *testing.T, target string) (root, base string) {
 	t.Helper()
+	t.Setenv("GIT_CONFIG_GLOBAL", os.DevNull)
+	t.Setenv("GIT_CONFIG_SYSTEM", os.DevNull)
+	t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
 	root = t.TempDir()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/unapproved_repo_test.go` around lines 15 - 42, Isolate
Git configuration in setupDomainDiffRepo and its gitTestCommand calls so fixture
initialization and commits do not inherit global excludes, templates, hooks,
init settings, or signing defaults. Reuse a per-fixture environment or explicit
Git configuration for all commands, while preserving the existing repository
setup and commit behavior.
lint/domaincontract/unapproved_test.go (1)

15-65: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicated sort/scan body. scanDomainEvidence and scanTypedDomainEvidenceInPackage differ only in whether Info is populated; extracting a shared collectSorted(file, fset, info) helper would remove the duplicated comparator.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/domaincontract/unapproved_test.go` around lines 15 - 65, Extract the
shared scan, evidence collection, and sorting logic from scanDomainEvidence and
scanTypedDomainEvidenceInPackage into a collectSorted helper accepting the
parsed file, file set, and optional types.Info. Update both callers to perform
only their distinct parsing/type-checking setup, then delegate to collectSorted
while preserving the existing host and expression-position ordering.
lint/main.go (1)

39-51: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider hoisting ScanOptions into lintapi. The scanner signature is keyed to errscontract.ScanOptions, forcing an adapter per additional domain. A shared lintapi.ScanOptions would let both scanners be registered directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lint/main.go` around lines 39 - 51, Move the shared scan-options type from
errscontract into lintapi, then update scanner.fn and all ScanRepoWithOptions
signatures to accept lintapi.ScanOptions. Adjust errscontract and domaincontract
implementations and callers accordingly, and register both scanners directly
without the domaincontract adapter closure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lint/domaincontract/diff.go`:
- Around line 157-171: Update gitCommandOutput to create a bounded context and
invoke git with exec.CommandContext instead of exec.Command. Ensure the context
timeout cancels hung git processes while preserving the existing output and
stderr-wrapping behavior.

In `@lint/domaincontract/policy.go`:
- Around line 58-65: Update the cross-list duplicate check to iterate hostnames
in deterministic sorted order rather than directly ranging over the fixtures
map. Preserve the existing duplicate error construction and return behavior,
using the sorted host keys before accessing fixtures and public.
- Around line 106-126: Update validatePolicyHostname to accept the same IDN
hostname forms recognized by normalizeCandidateHostname, while preserving
hostname length, label length, non-empty label, hyphen-boundary, and final-label
validation. Normalize accepted Unicode hostnames to punycode consistently with
the scanner before comparison, or otherwise allow valid non-ASCII letter/digit
labels so detected IDN hosts can be approved.

In `@lint/domaincontract/scan.go`:
- Around line 86-90: Add Go doc comments for the exported ScanOptions type, its
ChangedFrom field, and ScanRepoWithOptions. Document that ChangedFrom identifies
the base revision and an empty value requests a full inventory, matching the
behavior relied on by lint/main.go.

In `@lint/domaincontract/unapproved_repo_test.go`:
- Around line 15-42: Isolate Git configuration in setupDomainDiffRepo and its
gitTestCommand calls so fixture initialization and commits do not inherit global
excludes, templates, hooks, init settings, or signing defaults. Reuse a
per-fixture environment or explicit Git configuration for all commands, while
preserving the existing repository setup and commit behavior.

In `@lint/domaincontract/unapproved_test.go`:
- Around line 15-65: Extract the shared scan, evidence collection, and sorting
logic from scanDomainEvidence and scanTypedDomainEvidenceInPackage into a
collectSorted helper accepting the parsed file, file set, and optional
types.Info. Update both callers to perform only their distinct
parsing/type-checking setup, then delegate to collectSorted while preserving the
existing host and expression-position ordering.

In `@lint/main.go`:
- Around line 39-51: Move the shared scan-options type from errscontract into
lintapi, then update scanner.fn and all ScanRepoWithOptions signatures to accept
lintapi.ScanOptions. Adjust errscontract and domaincontract implementations and
callers accordingly, and register both scanners directly without the
domaincontract adapter closure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 45e92b0a-0ac3-4c0b-805e-6188c8bd86b8

📥 Commits

Reviewing files that changed from the base of the PR and between 0419c26 and b1fcb46.

📒 Files selected for processing (13)
  • internal/qualitygate/config/README.md
  • internal/qualitygate/config/allowlists/fixture-domains.txt
  • internal/qualitygate/config/allowlists/public-domains.txt
  • lint/README.md
  • lint/domaincontract/diff.go
  • lint/domaincontract/diff_test.go
  • lint/domaincontract/policy.go
  • lint/domaincontract/policy_test.go
  • lint/domaincontract/scan.go
  • lint/domaincontract/unapproved.go
  • lint/domaincontract/unapproved_repo_test.go
  • lint/domaincontract/unapproved_test.go
  • lint/main.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/qualitygate/config/README.md
  • lint/README.md

@HanShaoshuai-k
HanShaoshuai-k merged commit cfe76ad into main Jul 31, 2026
37 of 43 checks passed
@HanShaoshuai-k
HanShaoshuai-k deleted the feat/domain-allowlist branch July 31, 2026 03:02
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 31, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Architecture-level or global-impact change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants