From e71cb881c38c8d6f5e25f3f8771162c3cb099c70 Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Wed, 2 Dec 2026 11:04:19 +0100 Subject: [PATCH 1/2] Clarify safe startup exceptions in PR testing guidance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/copilot-instructions.md | 19 ++++- .github/skills/test-pr/SKILL.md | 128 ++++++++++++++++++++++++++++---- WINDOWS-VERIFICATION.md | 87 +++++++++++++++++----- 3 files changed, 196 insertions(+), 38 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 56cf4421..3a11e8e1 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -51,7 +51,7 @@ Path-specific rules live in `.github/instructions/` (CLI commands, JSON schemas) ## Testing Code Changes -When testing code, features, or changes, **always launch the proxy in detached mode** with these settings to avoid conflicts: +When testing code, features, or changes, use these **safe startup defaults** to avoid conflicts: ```bash dotnet run --project DevProxy -- --detach --as-system-proxy false --port 0 --api-port 0 @@ -61,9 +61,24 @@ dotnet run --project DevProxy -- --detach --as-system-proxy false --port 0 --api - `--port 0` — lets the OS assign a random available port for the proxy - `--api-port 0` — lets the OS assign a random available port for the API +Also pass `--install-cert false` to disable certificate trust installation. Keep system-proxy registration and trust installation disabled unless those behaviors are explicitly under test. + +Change only a default that prevents the required reproduction: +- **Foreground/TTY output or prompts:** omit `--detach`. +- **Configured-port validation:** omit the relevant CLI port override so the configuration value is tested. Keep the other override unless it also masks the scenario. +- **System-proxy lifecycle or native certificate trust:** test only in a disposable, isolated environment, such as a VM with separate native proxy settings and trust stores. A worktree, private certificate path, or isolated `HOME` alone is insufficient. Do not expose host settings, trust stores, credentials, or other users' traffic. If system-proxy registration requires certificate trust, explicitly include both behaviors in the test scope; do not bypass validation. + +Document each exception in the test matrix: the changed default, why it prevents reproduction, execution environment, safety controls, and cleanup verification. Use the [test-pr workflow](skills/test-pr/SKILL.md) for PR-specific examples and reporting requirements. + +For foreground runs, set a finite deadline, capture stdout/stderr separately or PTY output as appropriate, and verify readiness when a running proxy is required. Record launcher and child PIDs with process start times. Terminate only owned processes. Port-rejection cases must assert the expected diagnostic and exit status; runtime readiness is not required. + +Use private state, log, first-run, and certificate paths. Verify effective paths for the tested revision, including `DEV_PROXY_CERT_PATH`, and use the same private environment for startup, status, and cleanup. Private paths do not isolate native system changes. + +If an essential scenario cannot run safely, report **BLOCKED**, not **PASS**. Do not approve with essential scenarios blocked. These exceptions do not bypass higher-priority instructions. Identify any governing instruction that prevents an exception; repository edits cannot replace a governing copy already loaded into a session. Functional testing does not authorize fixing PR code or merging PRs. + **Auth for M365/Azure:** No automated auth. You can try `m365 util accesstoken get` or `az account get-access-token` (use `-h` for options) but the user may not be signed in. -**Cleanup:** After testing, stop the proxy using `devproxy stop` (preferred, cross-platform). If you started it with `dotnet run`, you can also stop it with `Ctrl+C` in that terminal; as a last resort, terminate the process using OS-specific tools (for example, `kill ` on Unix-like systems or Task Manager on Windows). Clean up any generated log files (`devproxy-*.log`). +**Cleanup:** Always clean up, including after failure or timeout. Stop only this run's instances using the matching build and `devproxy stop --pid ` (preferred, cross-platform). For foreground runs, send Ctrl+C only to the owned terminal/process. Before forced termination, verify the recorded PID and process start time; include owned launchers and children. Never stop all instances or kill processes by name. Verify owned processes and listeners are gone. Remove only this run's state, certificates, fixtures, and `devproxy-*.log` files after collecting sanitized evidence. For native-setting tests, record the proxy and trust-store baselines and the test certificate fingerprint, restore and verify those baselines inside the disposable environment, then dispose of it. Report cleanup failures. ## Reference (Architecture) diff --git a/.github/skills/test-pr/SKILL.md b/.github/skills/test-pr/SKILL.md index 548908f1..bfb8365b 100644 --- a/.github/skills/test-pr/SKILL.md +++ b/.github/skills/test-pr/SKILL.md @@ -72,7 +72,8 @@ Track progress with this checklist: - [ ] Inspect the PR and capture its head commit. - [ ] Check out the exact PR revision without disturbing local work. - [ ] Plan realistic functional scenarios. -- [ ] Start the PR build in detached mode and verify readiness. +- [ ] Start the PR build with safe defaults or a documented exception. +- [ ] Verify readiness or the expected startup rejection. - [ ] Execute scenarios and record evidence. - [ ] Stop owned processes and clean up test artifacts. - [ ] Check the report and comments against ASD-STE100. @@ -103,25 +104,67 @@ the PR's source build, not a globally installed Dev Proxy binary. Keep temporary configurations and fixtures in an owned `.devproxy` subdirectory; do not overwrite existing files. +Use private paths for state, logs, root certificates, and leaf certificates. +Verify the effective paths for the tested revision before execution. +Set `DEV_PROXY_CERT_PATH` to an owned path using that revision's path rules. +Keep the same private environment for launch, `status`, and `stop`. +Keep first-run state private when testing prompts. +A worktree or isolated `HOME` does not isolate system settings or native trust stores. + ### 3. Plan functional scenarios Create a concise test matrix before execution: -| Scenario | Setup and action | Expected observable result | -|----------|------------------|----------------------------| -| Changed behavior | Realistic configuration and client request | Exact response, output, or state | -| Failure or boundary case | Relevant invalid input or dependency failure | Defined error handling | -| Adjacent regression | Existing behavior affected by the change | Previous behavior preserved | +| Scenario | Setup and action | Expected observable result | Default changes and reason | Execution environment | Safety controls | Cleanup verification | +|----------|------------------|----------------------------|---------------------------|-----------------------|-----------------|----------------------| +| Changed behavior | Realistic configuration and client request | Exact response, output, or state | None, or each required exception | OS and private paths | Section 4 controls | Record verified cleanup | +| Failure or boundary case | Relevant invalid input or dependency failure | Defined error handling | None, or each required exception | OS and private paths | Section 4 controls | Record verified cleanup | +| Adjacent regression | Existing behavior affected by the change | Previous behavior preserved | None, or each required exception | OS and private paths | Section 4 controls | Record verified cleanup | Adapt the cases to the PR; do not add irrelevant tests just to fill the table. Translate each acceptance criterion into a measurable assertion, including status codes, headers, bodies, generated files, exit codes, or timing thresholds as appropriate. For a bug fix, include the reported reproduction. +For each exception, identify the changed default and explain why it prevents the reproduction. +Record the execution environment, safety controls, and planned cleanup checks before execution. +Record actual cleanup verification after execution, including failures and timeouts. +Change only the defaults that prevent the scenario. + +Use these examples when relevant: + +- [dotnet/dev-proxy#2138](https://github.com/dotnet/dev-proxy/pull/2138): + Omit `--detach` for foreground `--output json`. + Capture stdout and stderr separately. + Assert that each stdout line is valid JSON, with no blank lines. +- [dotnet/dev-proxy#2155](https://github.com/dotnet/dev-proxy/pull/2155): + Omit `--detach` for first-run prompts. + Use private first-run state and a pseudo-terminal (PTY) for interactive cases. + Check the prompt, input handling, and stdout/stderr behavior in JSON and text modes. + If the prompt requires `installCert: true`, use a disposable environment. + Document native trust as explicitly under test, even when the response declines installation. +- [dotnet/dev-proxy#2157](https://github.com/dotnet/dev-proxy/pull/2157): + Omit `--port 0` when testing configured `port`. + Omit `--api-port 0` when testing configured `apiPort`. + Keep the other override unless that case also tests its configuration value. + If detached startup hides rejection output or exit status, also document a foreground exception. + Test `-1` and `70000` for each property. + Assert the configuration diagnostic, exit status `1`, and absence of an unhandled stack trace. + Check that configured `0` still starts. +- [dotnet/dev-proxy#2149](https://github.com/dotnet/dev-proxy/pull/2149): + Enable the system proxy only in a disposable environment. + Check native registration during reload, endpoint changes, failed restart, and final shutdown. + Disabled system-proxy runs cannot prove registration retention. +- [dotnet/dev-proxy#2174](https://github.com/dotnet/dev-proxy/pull/2174): + Use private certificate paths to check that non-certificate commands create no root certificate. + Test native `cert ensure` and `cert remove` only in a disposable environment. + File creation alone does not prove native trust installation or removal. + Use deterministic mocks or local upstream services where possible. If external services, credentials, or platform-specific capabilities are essential, verify -availability and mark unavailable scenarios as blocked. Do not automate sign-in +availability and mark unavailable scenarios as **BLOCKED**. Do not automate sign-in or publish credentials. A mocked substitute does not prove a live integration. +If an essential scenario cannot run safely, mark it **BLOCKED**, not **PASS**. Select the smallest relevant existing build command. Rely on CI checks for the tested commit for automated test results; do not rerun automated tests locally @@ -132,15 +175,49 @@ runtime steps that are not applicable. ### 4. Start and verify Dev Proxy -For runtime scenarios, launch from the PR checkout using: +For runtime scenarios, use this default launch from the PR checkout: ```bash dotnet run --project DevProxy -- --detach --as-system-proxy false --port 0 --api-port 0 ``` Append `--config-file ` when a scenario needs a custom configuration. -Keep the safety flags for every launch: never change the system proxy or assume -fixed ports. Ensure schemas and plugin assemblies match the PR build. +Also pass `--install-cert false` to disable certificate trust installation. +Keep system-proxy registration and trust installation disabled unless explicitly under test. +Ensure schemas and plugin assemblies match the PR build. + +Use only these narrowly scoped exceptions: + +- **Foreground output or prompts:** Omit `--detach` when detached startup hides the required behavior. +- **Configured ports:** Omit only the relevant CLI port override to test the configuration value. + For valid fixed ports, check availability and prevent conflicts with other processes. +- **System-proxy lifecycle or native certificate trust:** Change the relevant setting only in a disposable, isolated environment. + Use a VM or equivalent environment with separate native proxy settings and trust stores. + Do not expose the host's settings, trust stores, credentials, or other users' traffic. + A worktree, private certificate path, or isolated `HOME` alone is insufficient. + Record the native baseline before changes. + Record the test certificate's fingerprint when the certificate is created. + Use only the privileges required for the scenario. + Respect permission and approval requirements. + +If the build requires certificate trust for system-proxy registration, explicitly include trust in the test matrix. +Use the disposable environment for both behaviors. +Do not bypass the build's validation. + +These exceptions do not override higher-priority instructions. +If a governing instruction prohibits an essential exception, mark the scenario **BLOCKED**. +Identify that instruction's source in the report. +An edit to repository instructions does not replace a governing copy already loaded into a session. + +For foreground runs, set a finite deadline before launch. +Capture stdout and stderr separately for assertions about each stream. +Use captured PTY output when the scenario requires terminal input or output. +If the PTY combines streams, use a separate capture case to verify stream-specific assertions. +Do not substitute redirected input for a required interactive terminal. +Record the launcher PID, child PIDs, and process start times. +Arrange cleanup for success, failure, and timeout before launch. +Terminate only processes owned by this run. +Record the observed exit status; a timeout is not an expected rejection. Capture the new instance's PID, assigned proxy port, API URL, and log file. Use that instance's startup output or PID-scoped status to discover endpoints; @@ -150,12 +227,17 @@ do not select an arbitrary running instance. For example: dotnet run --no-build --project DevProxy -- status --pid --output json ``` -Use a bounded readiness wait. Check that the process is alive, its API responds, +For scenarios that require a running proxy, use a bounded readiness wait. +Check that the process is alive, its API responds, and a client request explicitly routed through its assigned proxy port produces the expected smoke-test result. A status exit code of zero alone does not prove API availability. Use the instance's authentication mechanism where required; keep tokens out of published commands, output, and logs. +Port-rejection cases must assert the expected diagnostic and exit status. +They need not reach runtime readiness. +For other commands that do not start the proxy, check their output and required side effects instead. + If startup or readiness fails, inspect the owned instance's logs, record the failure, and do not execute dependent scenarios as though startup succeeded. @@ -174,17 +256,24 @@ report skipped or blocked tests as passing. ### 6. Clean up -Always clean up, including after failed tests. Stop only instances started by +Always clean up, including after failures and timeouts. Stop only instances started by this run, using `devproxy stop --pid ` with the matching build, or: ```bash dotnet run --no-build --project DevProxy -- stop --pid ``` -Verify the process exits. If graceful shutdown fails, terminate only the recorded -owned PID and report the cleanup issue. Never stop all running proxy instances. +Verify the process exits. +Before termination, match each recorded PID and process start time to prevent action on a reused PID. +If graceful shutdown fails, terminate only verified owned processes and report the cleanup issue. +Include owned foreground launchers and child processes. +Never stop all running proxy instances. Stop owned upstream services and remove only this run's temporary configurations, -fixtures, and generated `devproxy-*.log` files after collecting sanitized evidence. +fixtures, state, certificates, and generated `devproxy-*.log` files after collecting sanitized evidence. +Verify that owned processes and listeners are gone. +For native-setting tests, restore and verify the proxy and trust-store baselines inside the disposable environment. +Remove only the test certificate, identified by its fingerprint. +Record cleanup failures and dispose of the environment after collecting evidence. Restore the original checkout when safe, or remove the owned temporary worktree; preserve all pre-existing changes and files. @@ -199,7 +288,7 @@ Publish the test report without asking for confirmation. Choose the review event based only on evidence: - **Approve:** All necessary functional scenarios and required validation pass - on the current head. Scope the approval to functional testing; it does not + on the current head, with cleanup verified. Scope the approval to functional testing; it does not replace code review. - **Request changes:** A reproducible functional defect attributable to the PR prevents the expected behavior. Include reproduction steps, expected versus @@ -238,6 +327,13 @@ Complete the STE check before publishing the report or any review comments. |--------------------------|----------|--------|--------| | | | | PASS / FAIL / BLOCKED | +### Startup exceptions and cleanup + + +| Scenario | Changed default | Why the default prevents reproduction | Execution environment | Safety controls | Cleanup verification | +|----------|-----------------|---------------------------------------|-----------------------|-----------------|----------------------| +| | |