diff --git a/.gitignore b/.gitignore index 6cd5e01..b4bbc9d 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ coverage/ htmlcov/ .coverage coverage*.xml + +# Isolated source-build validation staging +/test-submodules/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b6096b..6202c01 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,9 +66,9 @@ package-version changes or publication and does not trigger or gate consumer submodule updates. Consumers are responsible for building both runtimes from their intended pinned -revision. Automated artifact-provenance enforcement and reliable build -invalidation remain roadmap S4 follow-up work rather than a package-version -release requirement. +revision. See [building from a pinned submodule](README.md#building-from-a-pinned-submodule) +for the build and packaging contract. Consumer pipeline enforcement and +compatibility testing remain extension-owned. ## Reporting Issues diff --git a/README.md b/README.md index 3f8a1d0..f4a8583 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,19 @@ remain supported. Neither identity is a registry-facing consumption API: do not add a bare dependency or registry install for it. This repository publishes neither npm nor PyPI packages. +### Building from a pinned submodule + +`npm run build` in `typescript` cleans `dist` before compiling, including outputs +for removed sources. Run it before type-checking or packaging the extension; +an existing `dist/index.js` is not a freshness check. + +For release CI, start from a fresh checkout with submodules initialized at their +recorded gitlinks. Check that the shared submodule matches the expected commit +and has no source changes. Build TypeScript and install Python from that same +checkout using the commands above, then package those outputs rather than +reusing artifacts from another pin. Consumer pipeline enforcement, dependency +locks, and compatibility tests remain the extension's responsibility. + ### Dependabot updates The consuming extensions configure Dependabot's `gitsubmodule` ecosystem to diff --git a/typescript/package.json b/typescript/package.json index 7892037..e3a9a2e 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -9,7 +9,7 @@ "dist/" ], "scripts": { - "build": "tsc", + "build": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\" && tsc", "watch": "tsc --watch", "lint": "eslint src", "format-check": "prettier --check src/**/*.ts", diff --git a/typescript/tests/build.test.ts b/typescript/tests/build.test.ts new file mode 100644 index 0000000..b57e465 --- /dev/null +++ b/typescript/tests/build.test.ts @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import { assert } from "chai"; +import { execFileSync } from "node:child_process"; +import { + existsSync, + mkdirSync, + mkdtempSync, + rmSync, + writeFileSync, +} from "node:fs"; +import * as path from "node:path"; + +suite("TypeScript build", () => { + test("removes obsolete JavaScript and declarations before compiling", function () { + this.timeout(60_000); + const npmCli = process.env.npm_execpath; + if (!npmCli) { + throw new Error("Run this test using npm test."); + } + const root = path.resolve(__dirname, "..", ".."); + const dist = path.join(root, "dist"); + mkdirSync(dist, { recursive: true }); + const stale = mkdtempSync(path.join(dist, "stale-build-")); + writeFileSync(path.join(stale, "removed.js"), "module.exports = {};\n"); + writeFileSync(path.join(stale, "removed.d.ts"), "export {};\n"); + try { + execFileSync(process.execPath, [npmCli, "run", "build"], { + cwd: root, + timeout: 60_000, + stdio: "pipe", + }); + assert.isFalse( + existsSync(stale), + "Outputs for removed sources must not survive the build", + ); + assert.isTrue(existsSync(path.join(dist, "index.js"))); + assert.isTrue(existsSync(path.join(dist, "index.d.ts"))); + } finally { + rmSync(stale, { recursive: true, force: true }); + } + }); +});