Skip to content

ci: enforce public-content rules with an intranet link check - #2635

Open
AlexStocks wants to merge 11 commits into
masterfrom
ci/public-content-check
Open

AlexStocks wants to merge 11 commits into
masterfrom
ci/public-content-check

Conversation

@AlexStocks

@AlexStocks AlexStocks commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

No issue is closed. This follows the public-content rules in #2633 and #2634 and adds an automated check for the URL patterns that can be identified locally.

Rationale for this change

Public repository content must not depend on corporate intranet documents. Written rules and manual review remain necessary for customer names, private resources on public hosts, and unlisted domains. A local hostname check can catch common intranet links before they are merged without making network requests.

What changes are included in this PR?

  • Add scripts/check_public_content.py, a standard-library-only checker for HTTP(S) URLs whose hostname equals or is a subdomain of antfin.com, alibaba-inc.com, alipay-inc.com, or aliyun-inc.com. It accepts explicit file paths or --all for tracked files, reports path:line diagnostics, and never rewrites content.
  • Extract the hostname from the complete URL authority before applying the suffix rule. Userinfo, ports, trailing dots, Chinese punctuation, Markdown delimiters, and public-host lookalikes are covered by regression tests.
  • Decode non-UTF-8 text lossily so ASCII links remain visible. Binary, oversized, and unreadable files are skipped and counted in the output. The size limit is 4 MiB.
  • Register the checker as a local prek hook. Existing make check execution already runs prek run -a, so no additional CI scan is needed.
  • Classify checker-only changes under the tests CI suite. Changes to shared pre-commit or CI policy still select full validation.
  • Prebuild Gateway before parallel Python end-to-end tests and use the downloaded Cargo dependencies offline during those tests. Cold downloads, compilation, and Cargo lock waits no longer consume concurrent fixture deadlines.
  • Use eight workers for the parallel Python unit and e2e jobs after 32-worker runs missed service and subprocess deadlines. Run the Topic Memory head-conflict scenario serially after Gateway prebuild, with its existing assertions and deadlines. Allow each test matrix job to finish so a failure in one Python version does not cancel another version's tests.
  • Align AGENTS.md, CONTRIBUTING.md, and both RFC READMEs with the automated check and its limits. Add manual public-content and locale-parity checkboxes to the PR template.

The checker matches four fixed host suffixes; it does not verify reachability or determine whether arbitrary content is public. Bare domains, protocol-relative links, binary or oversized content, other intranet domains, private document IDs, SSO-only spaces on public hosts, and external names still require manual review. Local examples such as *.internal.example and host.docker.internal remain allowed.

Run the check directly with:

uv run python scripts/check_public_content.py --all

Are there any user-facing changes?

No runtime, API, dependency, or persisted-format change. Contributors receive a failing prek/CI check with file and line diagnostics for matched links, plus a count of files the checker could not scan.

How was this change tested?

Gateway CI setup validation on WSL/Linux (Python 3.13.14, Rust 1.95.0):

  • cargo build --locked --manifest-path gateway/Cargo.toml --target-dir gateway/target -p pc-gateway-app: passed.
  • CARGO_NET_OFFLINE=true uv run --no-sync pytest -n 4 tests/e2e/test_gateway_authentication.py tests/e2e/test_gateway_http1_lifecycle.py -k 'not earlier_request' -q: 40 passed. These tests use real Gateway and Python Core processes with controlled local providers.
  • The focused local rerun excludes the existing 180-second request-deadline case. CI still runs that case and the full end-to-end suite; acceptance assertions and fixture deadlines are unchanged.
  • The local WSL build used the system linker through process-local RUSTFLAGS because the installed toolchain lacks its bundled linker. No repository linker or proxy configuration changed.
  • YAML, merge-conflict, newline, whitespace and public-content hooks on the workflow file passed; git diff --check passed.

Python 3.12 CI worker validation on WSL/Linux

  • All ten cases that failed in the second 32-worker CI run passed with eight workers after prebuilding Gateway.
  • Gateway prebuild and the eight-worker e2e suite passed in GitHub Actions on Python 3.12, 3.13, and 3.14. Python 3.11 timed out in the Topic Memory head-conflict scenario, which passed serially in a Linux Python 3.11 checkout.
  • Twelve representative unit cases from the 32-worker failure logs passed with eight workers on Linux Python 3.12. Workflow YAML, dry runs of both Make targets, and the workflow file hooks passed.

Validation on the branch containing master 6763b07661846c19934044184995adf9183c28cc:

  • uv run --no-sync pytest tests/test_check_public_content.py tests/test_ci_changes.py -q: 174 passed, including all 9 checker regression tests.
  • uv run --no-sync ruff check --no-fix scripts/check_public_content.py tests/test_check_public_content.py: passed.
  • uv run --no-sync ruff format --check scripts/check_public_content.py tests/test_check_public_content.py: passed.
  • uv run --no-sync ty check --python-version 3.11 scripts/check_public_content.py tests/test_check_public_content.py: passed.
  • uv run --no-sync python scripts/check_public_content.py --all: 3,932 files checked, 116 skipped, no matching URLs.
  • uv run --no-sync prek run check-public-content --all-files: passed.
  • CI selector probe: a change only to scripts/check_public_content.py selects exactly tests; the unclassified input selected all 32 suites before the rule was added.
  • git diff --check: passed.

Full local prek run -a was attempted but did not pass on Windows: tracked observability symlinks are materialized as text, and the native-platform type check reports POSIX-only APIs. The hook's newline edits to those symlink placeholders were restored. A supplementary type check targeting Linux, excluding the unmaterialized deploy/observability/stats-proxy.py symlink, passed; this is not equivalent to a full Linux CI run. The pushed head triggers CI for validation in the supported runner environment.

AI usage statement

WorkBuddy and OpenAI Codex assisted with the checker, regression tests, rule documentation, CI path classification, Gateway prebuild configuration, and validation. The commands reported above were executed locally and their outputs inspected.

Public content review

  • No external customer, user, partner, or internal project names appear anywhere.
  • No internal or SSO-only document links; docs/en/ and docs/zh/ carry the same wording and references.

Written rules from #2634 rely on a manual grep. Add scripts/check_public_content.py, wire it into pre-commit (CI runs prek via make check -> workflow-actions-check), add regression tests and a PR checklist for names that cannot be matched mechanically, and point CONTRIBUTING.md / AGENTS.md / both RFC READMEs at the enforced command. No runtime or API change.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 15:26

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@AlexStocks

Copy link
Copy Markdown
Contributor Author

Scope and limits of this gate

This PR is the enforcement layer for the two earlier ones: #2633 removed the link, #2634 wrote the rules, and this one makes the mechanically detectable part fail CI rather than depending on a contributor remembering a self-check command.

Three things the gate intentionally does not cover, so reviewers know what still needs human attention:

  1. External customer / user / partner names. There is no generic pattern for them, and hard-coding a name into a deny-list would itself publish that name in a public repository. The two PR-template checkboxes are the only guard; please read both docs/en/ and docs/zh/ rather than trusting CI here.
  2. SSO-only resources hosted on public domains. The checker matches exact intranet host suffixes (antfin.com, alibaba-inc.com, alipay-inc.com, aliyun-inc.com). A private space on a public SaaS domain is indistinguishable from a public link to a machine. Deliberately, no generic *.internal rule was added: the tree has 7 legitimate local-example occurrences (powercontext.internal.example, host.docker.internal) that would fail CI immediately.
  3. PR / issue bodies and git history. pre-commit only sees repository files. This PR does not scan PR descriptions and does not rewrite history; the link and name removed in docs(rfc): remove inaccessible internal requirement link from RFC 1614 #2633 remain reachable in earlier commits. If compliance requires purging them from history, that is a separate maintainer decision and is not attempted here.

To extend coverage, add a suffix to INTERNAL_HOST_SUFFIXES in scripts/check_public_content.py and extend tests/test_check_public_content.py in the same PR.

Validation performed locally: 4 pytest tests passed; ruff check/format and ty check clean; check_public_content.py --all over 3944 tracked files with 0 findings (master baseline was 0); prek run check-public-content --all-files Passed; and an injected intranet URL made the hook exit 1 with a path:line diagnostic (the probe was removed byte-for-byte afterward).

@AlexStocks AlexStocks added the 1.5.2 v1.5.2 release tracking label Nov 13, 2026
Fix the P1 false negative from self-review: the host capture now accepts only URL-authority characters, so CJK punctuation, full-width delimiters and Markdown backticks no longer become part of the hostname. Add regression tests for those forms and for public links next to the same delimiters. Fix P2 by stating the fixed INTERNAL_HOST_SUFFIXES list in CONTRIBUTING.md, AGENTS.md and both RFC READMEs, including what still needs a manual read.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:16

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

…d files

Second self-review found that a UnicodeDecodeError skipped a whole legacy-encoded text file, files over 4 MB were skipped, and skipped files were still counted as checked, producing a misleading success message. Decode text lossily, report scanned and skipped counts separately, state the remaining detection boundaries in the rule documents, and add two regression tests plus four mutation counter-proofs. Split scanning into scan_files() to satisfy the C901 complexity limit.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:51

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • CI failed: CI result (failure).
  • CI failed: desktop-validation / linux (failure).
  • CI failed: cindy-package (failure).
  • CI failed: dsh-package (failure).
  • CI failed: Main (failure). Failed steps: dsh-package / Test DSH package; cindy-package / Build and test the standalone Cindy archive; desktop-validation / linux / Run cargo clippy --locked --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings.

Comment thread scripts/check_public_content.py Resolved
Copilot AI balanced review requested due to automatic review settings November 14, 2026 04:17

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@AlexStocks

Copy link
Copy Markdown
Contributor Author

CI rerun after a base update

The failures in run 43467000459 were not caused by this PR. Its eight files are documentation, a pre-commit hook, a checker script, and its tests; none of them touch the TypeScript bundles or the Rust desktop crate. All three failing jobs came from the old base 9924bb4:

I used Update branch to merge master into this branch (c18f347). The diff against the new base is still exactly the same eight files, both bundle blobs now match master byte-for-byte, and the return is gone. Run 43555935194 was triggered on the updated head; CI preflight (including prek run -a and the new check-public-content hook), docs-tests, check-website, and website-link-validation-windows have passed so far.

@hidb4ai hidb4ai 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.

Reviewed c18f3476b6eda2edf85c80e1d11e619b8fa2c46c. Requesting changes for the unresolved URL-authority parsing defect: the configured hook reports success for a prohibited hostname when userinfo contains +. I added the hook-level reproduction to the existing thread.

@hidb4ai hidb4ai removed the 1.5.2 v1.5.2 release tracking label Nov 15, 2026
@AlexStocks AlexStocks added the 1.6.0 v1.6.0 release tracking label Nov 17, 2026
Comment thread .pre-commit-config.yaml Resolved
`URL_RE` captured only `[A-Za-z0-9._:@-]+`, so a userinfo sub-delimiter
(`+ ! $ & ' ( ) * , ; =`), a `~`, or a percent-encoded password truncated the
match before the host. The suffix check then ran on the userinfo: a public
document URL with `user+tag@` in front of a listed intranet host produced the
finding candidate `user`, matched no suffix, and was accepted, while the same
link without userinfo was rejected.

The capture now stops at `/ ? #` or whitespace, and `hostname_of()` keeps the
leading DNS-label run of the authority after splitting off the userinfo. Ports,
trailing dots, CJK punctuation, brackets, quotes and backticks are dropped by
that prefix instead of by narrowing the character class, so the existing
punctuation and public-host guards keep passing unchanged.

Coverage: 16 userinfo forms (sub-delimiters, password, percent-encoding, port),
plus a guard that a public destination whose userinfo mentions an intranet host
stays accepted and that lookalike hosts are still not matched.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 13:52

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Classify the public-content checker with its unit tests so future checker-only changes do not fall back to every CI suite. Keep the checker and existing regression coverage.

Constraint: Shared pre-commit and CI policy changes still select full validation.
Scope-risk: CI path selection only; no runtime or checker behavior change.
Tested: 174 focused tests passed; Ruff and focused ty checks passed; checker scan and configured hook passed; checker-only routing selects tests. Full local prek remains blocked by Windows symlink materialization and POSIX-only APIs.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 07:20

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

The PR's e2e rerun timed out while Cargo fixtures waited for package-cache
and artifact-directory locks. Download and compile the Gateway before
starting pytest workers, then keep their incremental Cargo checks offline.

Constraint: Preserve the Gateway behavior, acceptance assertions and fixture deadlines.
Scope-risk: CI setup only; failed cold builds stop before tests instead of surfacing as fixture timeouts.
Tested: Gateway cargo build --locked; WSL Python 3.13 pytest -n 4 tests/e2e/test_gateway_authentication.py tests/e2e/test_gateway_http1_lifecycle.py -k 'not earlier_request' -q (40 passed); checker and CI-selector tests (174 passed); YAML, whitespace and public-content hooks; git diff --check.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 23:56

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Two runs with 32 workers on the same head missed service startup,
request, and spawned-worker deadlines. Use eight workers for the Python
3.12 e2e job via the existing Makefile setting.

Constraint: Keep the existing cases and their deadlines.
Scope-risk: Python 3.12 e2e may take longer on well-provisioned runners.
Tested: The ten cases that failed in attempt 2 passed on Linux with Python 3.12 and pytest -n 8. Checked workflow YAML and make -n e2e-test with and without PYTEST_WORKERS=8.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 07:50

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

The topic worker timed out under 32 xdist workers on both Python 3.11 and 3.12. Apply the eight-worker setting to every e2e job and retain each matrix result.

Constraint: Preserve all tests and deadlines.

Scope-risk: Lower e2e concurrency and allowing matrix jobs to finish can increase CI time on some runs.

Tested: Parsed workflow YAML, verified the Makefile worker override, and ran the ten failed scenarios from run 44840366770 attempt 2 with pytest -n 8 on Linux.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 08:22

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Unit jobs on all four Python versions hit child-process deadlines at 32 workers. Use the existing eight-worker limit for both suites. Run the Topic Memory head-conflict scenario serially after its 3.11 timeout at both 32 and eight workers.

Constraint: Keep all cases and existing deadlines.

Scope-risk: Smaller unit-test pools can take longer on unconstrained runners.

Tested: Python 3.11 serial Topic Memory scenario and 12 representative unit failures on Python 3.12 with pytest -n 8 passed on Linux. Workflow YAML, make dry runs, and file hooks passed.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 08:58

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@AlexStocks AlexStocks closed this Nov 21, 2026
@AlexStocks AlexStocks reopened this Nov 21, 2026

@hidb4ai hidb4ai 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.

The previous userinfo and CI-path classification issues are fixed. Requesting changes for a new URL-boundary regression: markup following a pathless URL can now change the hostname being checked. Confirmed through both the standalone checker and the configured prek hook.

# follow a bare URL in Chinese docs or Markdown inline code (full-width
# punctuation, brackets, quotes, backticks) is dropped by HOSTNAME_PREFIX_RE
# below rather than by narrowing this capture.
URL_RE = re.compile(r"https?://([^\s/?#]+)", re.IGNORECASE)

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.

[P2] Bound the URL before interpreting userinfo

For url = "https://" + "yuque.antfin.com", a UTF-8 file containing f'<a href="{url}">contact@example.com</a>' now exits 0 and the configured prek hook passes; c18f3476 correctly rejected it. The capture includes ">contact@example.com<, so rsplit("@", 1) checks the link text's domain instead of the actual href. The inverse also regresses: a public GitHub href with an intranet email as its label is falsely rejected. Please establish the URL's markup/text boundary before removing userinfo, while preserving the newly fixed legal userinfo forms, and cover both directions with regression cases.

@AlexStocks AlexStocks added 1.6.1 v1.6.1 release tracking and removed 1.6.0 v1.6.0 release tracking labels Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.1 v1.6.1 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants