Skip to content

Commit b10d39a

Browse files
edvilmeCopilot
andauthored
Fix npm release network isolation (#1987)
## Summary - Select `Preferred,GitHub,NodeTool` network isolation policy for checkout and Node installation while preserving enforced isolation and required restrictions. - Reuse the existing authenticated Azure Artifacts npm setup in build and publish jobs. No new secrets or GitHub API tokens are introduced. - Remove GitHub release lookups and source-provenance validation entirely, including the Azure provenance step, HTTP retry/tag-resolution/source-comparison helpers, and their obsolete tests. - Keep local exact stable minimum-version validation, generated runtime floors, packed manifest/ESM/CommonJS consistency checks, and package consumer tests. The selected minimum need not equal the newest stable extension. - Defer any new release-PR gate or publication branch-policy changes to a separate PR. For now, release authors must confirm that the selected minimum has shipped the required APIs. - Update documentation and changelog. Preserve publication conditions, approvals, and the `no-merge` hold. ## Validation - Node 22.21.1: API compilation, local release validation, all 4 remaining release-validator tests, and packed modern/legacy TypeScript plus ESM/CommonJS consumer checks passed. - Default, `--artifact`, and `--artifact-directory` CLI modes pass with fetch blocked, including an older 1.40.0 artifact; compiled-floor mismatches are still rejected. - Repository lint, TypeScript compilation, and 3,511 unit tests passed (9 pending). - Code/YAML formatting, YAML parsing, and `git diff --check` passed. Verified that the PR workflow and Azure publication condition are unchanged by this follow-up and no provenance callers remain. - **A fresh official build-only run at commit `a271744b` or the current PR HEAD is still required.** Use `quality=stable` and `publishPackage=false`. Preserve `no-merge` until this run succeeds. ## Release follow-up This includes an `api/package.json` script change, so merging can trigger an official build, but the npm version is unchanged and will not automatically trigger publication. After validation, review, and merge, queue a **new** official run at the fixed main commit with `quality=stable` and `publishPackage=true`. Do not retry an old run using its original YAML/code. The failed dry run did not publish npm 1.8.0, so no additional package version bump is needed. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7992926e-a6ef-49ad-b6c9-120b52c0de51
1 parent 0f7bcaf commit b10d39a

9 files changed

Lines changed: 62 additions & 274 deletions

File tree

‎.github/workflows/pr-check.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ jobs:
5151
run: npm ci
5252
working-directory: api
5353

54-
- name: Validate latest stable extension baseline
54+
- name: Validate declared extension minimum
5555
if: steps.scope.outputs.relevant == 'true'
5656
run: npm run check:release
5757
working-directory: api
58-
env:
59-
GITHUB_TOKEN: ${{ github.token }}
6058

6159
- name: Build and test API package
6260
if: steps.scope.outputs.relevant == 'true'

‎CONTRIBUTING.md‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,23 @@ Its generated `api/src` sources are **not committed** (see [`api/.gitignore`](./
125125
constant. Install dependencies with `npm --prefix api ci` first.
126126
- Run `npm --prefix api test` after compilation. This tests the release validator
127127
and packs/installs the package for modern/legacy TypeScript and ESM/CommonJS
128-
runtime checks. `npm --prefix api run check:release` checks the live baseline;
129-
add `-- --provenance` to verify original and staged sources against that release.
128+
runtime checks. `npm --prefix api run check:release` validates the declared
129+
minimum locally without network requests.
130130
- Shared API sources are also checked by the extension's lint and TypeScript
131131
compile. The PR's **API package compatibility** job builds/tests npm release
132-
inputs and validates their minimum against the latest stable release.
133-
Documentation-only and unrelated PRs do not perform the external lookup.
132+
inputs and validates their declared minimum without a GitHub lookup.
134133
Configure that job as a required check in branch protection.
135134

136135
### API versioning and publication
137136

138137
The npm version in [`api/package.json`](./api/package.json) is independent of the
139138
extension version in [`package.json`](./package.json). Each new npm release must
140-
declare `minimumExtensionVersion` as an exact stable SemVer matching GitHub's
141-
designated latest stable extension release tag (without its leading `v`). Ranges,
142-
prerelease floors, and build metadata are rejected. The helper checks installed
143-
extension versions before activation using normal SemVer precedence, including
144-
already-active extensions. Published npm releases keep their original minimum.
139+
declare `minimumExtensionVersion` as an exact stable SemVer identifying the
140+
chosen supported extension release (without its leading `v`). It need not be the
141+
latest release. Ranges, prerelease floors, and build metadata are rejected.
142+
The helper checks installed extension versions before activation using normal
143+
SemVer precedence, including already-active extensions. Published npm releases
144+
keep their original minimum.
145145

146146
Defer npm version bumps to release PRs by applying `skip api version` to API
147147
implementation PRs. Any PR editing a shared public API source or
@@ -154,21 +154,18 @@ Release in this order: merge API changes without an npm version bump, ship the
154154
stable extension, then merge an npm release PR updating
155155
`minimumExtensionVersion`, the npm version, and the changelog. The stable npm
156156
version bump starts the publication pipeline automatically. Development can merge
157-
before the extension ships: source provenance is checked at packaging, not on PRs.
158-
The npm pipeline resolves the stable release tag to an immutable commit and
159-
requires all five shared source files, including their staged copies, to match.
160-
Only line-ending differences are ignored; even comment-only differences block
161-
publication. This conservative provenance check is not a semantic API analyzer.
162-
The npm-only wrapper can evolve without changing those shared extension sources.
157+
before the extension ships. Release authors must confirm that the declared
158+
minimum contains the APIs required by the npm package. Automated GitHub release
159+
and source-provenance checks are deferred to a separate PR; neither PR checks
160+
nor the publication pipeline currently performs those lookups.
163161

164162
The packed manifest and both compiled runtime floors must agree. The publish
165-
stage checks the actual tarball against the latest stable release again. If a
166-
new stable release appeared during review or between packaging and publishing,
167-
explicitly update the minimum, rebuild, retest, and rerun the pipeline; do not
168-
restamp the existing artifact. Both `latest` and `next` npm tags currently use
169-
this stable baseline: preview-only API publishing needs a separate policy.
170-
Public GitHub lookups use bounded retries and fail closed. Local runs can set
171-
`GITHUB_TOKEN` to avoid anonymous rate limits; PRs use their read-only token.
163+
stage checks this metadata in the actual tarball locally, without a GitHub
164+
lookup. A newer stable extension does not invalidate the selected baseline or
165+
require repacking. To change the minimum, update the manifest, rebuild, retest,
166+
and rerun the pipeline; do not restamp the existing artifact. Both `latest` and
167+
`next` npm tags currently use a stable baseline: preview-only API publishing
168+
needs a separate policy.
172169

173170
- **Releasing:** merging a stable version change in `api/package.json` into `main` automatically starts the [npm pipeline](./build/azure-pipeline.npm.yml), including its existing build, package tests, and MicroBuild approval process. Other manifest edits build and validate the package without publishing. The version check compares the merged commit with its parent, relying on the repository's squash-only merge policy; direct pushes to `main` also trigger it. Preview releases remain manual: queue the pipeline with `quality: preview` and `publishPackage: true`. Manual runs otherwise remain build-only unless `publishPackage` is explicitly enabled.
174171

‎api/CHANGELOG.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `minimumExtensionVersion` metadata recording the independently versioned extension baseline required by this npm release.
1313
- An npm-only compatibility guard that rejects older or invalid extension versions before activation or access to the API, with localized update guidance.
14-
- PR validation against the latest stable extension release, packed-metadata checks, and publish-time verification that shared API sources have shipped in that stable release.
14+
- Local validation of the declared extension minimum and packed-metadata consistency checks.
1515

1616
### Changed
1717

18-
- New npm releases require the latest stable extension baseline. Existing npm releases keep their original minimum; consumers targeting older extensions may need to pin an older npm package.
18+
- New npm releases select a supported stable extension baseline rather than requiring the latest release. Existing npm releases keep their original minimum.
1919

2020
### Notes
2121

‎api/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ accepts `1.40.0`, `1.40.1`, and `1.41.0` (including odd-minor preview-channel bu
4949
but rejects `1.40.0-rc.1`. A newer prerelease such as `1.41.0-rc.1` meets that floor.
5050
Build metadata does not affect ordering.
5151

52-
The minimum is fixed for an already-published npm release. New npm releases use the
53-
latest stable extension as their baseline, which can raise the minimum even when
54-
their API changes would otherwise work on an older extension. Pin an older npm
55-
package if your extension must retain support for an older runtime.
52+
The minimum is fixed for an already-published npm release. New npm releases select
53+
a supported stable extension as their baseline; it need not be the newest stable
54+
release. A newer extension release alone does not raise this minimum. If an npm
55+
update raises the floor beyond your supported runtime, pin an older npm package.
5656

5757
Acquire the API through this helper: type-only imports and direct access to the
5858
extension's exports bypass the check. The floor does not replace feature detection

‎api/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"scripts": {
4141
"prepublishOnly": "echo \"⛔ Can only publish from a secure pipeline ⛔\" && node -e \"process.exitCode = 1\"",
4242
"prepack": "npm run all:publish",
43-
"all:publish": "npm ci && npm run compile && npm run check:release -- --provenance && npm test",
43+
"all:publish": "npm ci && npm run compile && npm run check:release && npm test",
4444
"copy:sources": "node ./scripts/copy-sources.cjs",
4545
"compile": "npm run copy:sources && npm run clean && npm run compile:types && npm run compile:esm && npm run compile:cjs",
4646
"compile:types": "tsc -b ./tsconfig.types.json",

‎api/scripts/check-extension-version.cjs‎

Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ const fs = require('node:fs');
55
const path = require('node:path');
66
const { execFileSync } = require('node:child_process');
77
const { parseArgs } = require('node:util');
8-
const { setTimeout: sleep } = require('node:timers/promises');
98
const semver = require('semver');
109

11-
const repository = 'microsoft/vscode-python-environments';
1210
const sharedSources = ['api.ts', 'types.ts', 'publicErrors.ts', 'capabilities.ts', 'legacyCapabilities.ts'];
1311

1412
/** Returns the manifest's canonical stable SemVer floor, rejecting ranges and prerelease versions. */
@@ -27,97 +25,6 @@ function validateMinimumExtensionVersion(manifest) {
2725
return version;
2826
}
2927

30-
/** Reads public repository metadata with bounded retries for transient failures only. */
31-
async function requestGitHub(resource, { fetchImpl = fetch, token = process.env.GITHUB_TOKEN, wait = sleep } = {}) {
32-
for (let attempt = 0; attempt < 3; attempt += 1) {
33-
let response;
34-
try {
35-
response = await fetchImpl(`https://api.github.com/repos/${repository}/${resource}`, {
36-
headers: {
37-
Accept: 'application/vnd.github+json',
38-
'User-Agent': 'python-environments-api-release-check',
39-
...(token ? { Authorization: `Bearer ${token}` } : {}),
40-
},
41-
signal: AbortSignal.timeout(15000),
42-
});
43-
} catch (error) {
44-
if (
45-
attempt === 2 ||
46-
!(error instanceof TypeError || error.name === 'AbortError' || error.name === 'TimeoutError')
47-
) {
48-
throw error;
49-
}
50-
await wait(1000 * 2 ** attempt);
51-
continue;
52-
}
53-
if (response.ok) {
54-
return response.json();
55-
}
56-
const retryable =
57-
response.status === 429 ||
58-
response.status >= 500 ||
59-
(response.status === 403 &&
60-
(response.headers.get('x-ratelimit-remaining') === '0' || response.headers.has('retry-after')));
61-
if (!retryable || attempt === 2) {
62-
throw new Error(
63-
`GitHub lookup failed (${response.status}) for ${resource}. Retry the check after resolving the lookup failure.`,
64-
);
65-
}
66-
const retryAfter = Number(response.headers.get('retry-after'));
67-
await wait(Math.min(10000, Math.max(1000 * 2 ** attempt, retryAfter * 1000 || 0)));
68-
}
69-
}
70-
71-
/** Resolves GitHub's designated latest stable release, not the development manifest or preview channel. */
72-
async function getLatestStableRelease(options) {
73-
const release = await requestGitHub('releases/latest', options);
74-
if (release?.draft !== false || release.prerelease !== false || typeof release.tag_name !== 'string') {
75-
throw new Error('GitHub did not return a valid latest stable extension release.');
76-
}
77-
const version = validateMinimumExtensionVersion({ minimumExtensionVersion: release.tag_name.replace(/^v/, '') });
78-
return {
79-
version,
80-
tag: release.tag_name,
81-
url: `https://github.com/${repository}/releases/tag/${encodeURIComponent(release.tag_name)}`,
82-
};
83-
}
84-
85-
/** Enforces the new-npm-release policy without modifying already-published package metadata. */
86-
function assertLatestStable(manifest, release) {
87-
const minimum = validateMinimumExtensionVersion(manifest);
88-
if (minimum !== release.version) {
89-
throw new Error(
90-
`minimumExtensionVersion is ${minimum}; latest stable is ${release.version} (${release.url}). Update api/package.json, rebuild, and rerun validation.`,
91-
);
92-
}
93-
}
94-
95-
/** Rejects unreleased shared API sources, including stale staged copies, at packaging time. */
96-
async function verifySourceProvenance(packageRoot, release, options) {
97-
let object = (await requestGitHub(`git/ref/tags/${encodeURIComponent(release.tag)}`, options)).object;
98-
for (let depth = 0; object?.type === 'tag' && depth < 5; depth += 1) {
99-
object = (await requestGitHub(`git/tags/${object.sha}`, options)).object;
100-
}
101-
if (object?.type !== 'commit' || !/^[a-f0-9]{40}$/.test(object.sha)) {
102-
throw new Error(`Cannot resolve ${release.tag} to an immutable release commit.`);
103-
}
104-
const normalize = (contents) => contents.replace(/\r\n/g, '\n');
105-
for (const source of sharedSources) {
106-
const remote = await requestGitHub(`contents/src/${source}?ref=${object.sha}`, options);
107-
if (remote.encoding !== 'base64' || typeof remote.content !== 'string') {
108-
throw new Error(`Cannot read released API source src/${source} at ${object.sha}.`);
109-
}
110-
const released = normalize(Buffer.from(remote.content, 'base64').toString('utf8'));
111-
for (const local of [path.join(packageRoot, '..', 'src', source), path.join(packageRoot, 'src', source)]) {
112-
if (normalize(fs.readFileSync(local, 'utf8')) !== released) {
113-
throw new Error(
114-
`${local} differs from ${release.tag} (${object.sha}). Publish the stable extension containing these API sources, then update the npm baseline and rebuild.`,
115-
);
116-
}
117-
}
118-
}
119-
}
120-
12128
/** Checks the packed manifest and both compiled metadata modules without executing package code. */
12229
function validatePackedArtifact(artifact) {
12330
const read = (entry) =>
@@ -138,10 +45,9 @@ function validatePackedArtifact(artifact) {
13845
return manifest;
13946
}
14047

141-
async function main() {
48+
function main() {
14249
const { values } = parseArgs({
14350
options: {
144-
provenance: { type: 'boolean', default: false },
14551
artifact: { type: 'string' },
14652
'artifact-directory': { type: 'string' },
14753
},
@@ -162,28 +68,21 @@ async function main() {
16268
const manifest = artifact
16369
? validatePackedArtifact(artifact)
16470
: JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
165-
validateMinimumExtensionVersion(manifest);
166-
const release = await getLatestStableRelease();
167-
assertLatestStable(manifest, release);
168-
if (values.provenance) {
169-
await verifySourceProvenance(packageRoot, release);
170-
}
171-
process.stdout.write(`Extension compatibility baseline verified: ${release.version} (${release.url}).\n`);
71+
const minimum = validateMinimumExtensionVersion(manifest);
72+
process.stdout.write(`Extension compatibility baseline verified: ${minimum} (declared minimum).\n`);
17273
}
17374

17475
module.exports = {
17576
sharedSources,
17677
validateMinimumExtensionVersion,
177-
requestGitHub,
178-
getLatestStableRelease,
179-
assertLatestStable,
180-
verifySourceProvenance,
18178
validatePackedArtifact,
18279
};
18380

18481
if (require.main === module) {
185-
main().catch((error) => {
82+
try {
83+
main();
84+
} catch (error) {
18685
process.stderr.write(`${error.message}\n`);
18786
process.exitCode = 1;
188-
});
87+
}
18988
}

0 commit comments

Comments
 (0)