Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/package-feed.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Advisory unless "Package Feed Check" is added to required checks in branch protection / rulesets.
# Advisory unless the individual job names are added to required checks in branch protection / rulesets.
# A failed check stays red; optional does not mean suppressing policy, network or authentication failures.
name: Package Feed Check
name: Advisory Checks

permissions:
contents: read
Expand Down Expand Up @@ -41,3 +41,27 @@ jobs:
# No npm ci or secrets: the checker uses only Node built-ins and the no-auth Microsoft proxy.
- name: Check package feed policy and availability
run: npm run feed:check -- --visibility public

coda-freshness:
name: CODA Freshness
# Temporarily paused until hosted freshness verification and private-source access are needed.
if: ${{ false }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
package-manager-cache: false

# Independent optional job, not continue-on-error: stale/unverifiable is red without cancelling other checks.
# Never expose private-source credentials to PR code, including same-repository PRs.
- name: Compare configured CODA branch HEAD and pin
env:
CODA_READ_TOKEN: ${{ github.event_name != 'pull_request' && secrets.CODA_READ_TOKEN || '' }}
run: npm run coda:check
19 changes: 18 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ another revision; normal builds and unit tests never fetch or repin CODA.
npm run fetch-coda
npm run test:coda -- --detectors DX-001,DX-011,DX-020
npm run test:coda
npm run coda:check
```

The fetch command requires Git and access to the configured private Azure DevOps repository through your existing
Expand All @@ -55,11 +56,27 @@ not-selected counts. This report and downloaded files are private, Git-ignored,
excluded from VSIX packaging. Do not upload them to public logs or artifacts. Public GitHub Actions execution is refused
unless an operator explicitly sets `CODA_TRUSTED_PRIVATE_RUNNER=1` on a genuinely trusted private runner.
Ordinary contributors without private-source access can run the infrastructure's synthetic unit tests without CODA.
`npm run test:coda-tools` checks download integrity against disposable local Git repositories.
`npm run test:coda-tools` checks download integrity and freshness relationships against disposable local Git repositories.
It runs as an independent yellow `coda-tools` branch alongside magenta Vitest and cyan migration-skill tests in both
`npm run vitest` and `npm run vitest:coverage`. Parser/binding regressions do not need private-source access.
Public CI against the original contracts requires an approved redistributable upstream bundle.

`npm run coda:check` compares the configured `trackingRef` HEAD with the immutable pin without repinning or touching the
conformance cache. Equality exits 0; a mismatch exits 1 with exact upstream-ahead and upstream-behind commit counts.
Rewound, divergent and unrelated histories are distinguished. Authentication, missing refs/objects and network errors
also fail explicitly as unverifiable. History is fetched into a disposable bare repository, never checked out or executed.

The existing package-feed workflow has an independent `CODA Freshness` advisory job. It is temporarily disabled for all
hosted triggers with `if: ${{ false }}` until server-side verification and private-source access are needed. The job
appears as skipped, not as verified current; local `npm run coda:check` remains available.
When re-enabled, failures remain red without cancelling the package-feed job or adding dependencies to build/package
workflows. Keep this job optional in branch rulesets; required-check configuration is an owner responsibility and is not
changed by the workflow.
Push/manual runs can use an owner-configured read-only Azure DevOps `CODA_READ_TOKEN` secret. Git credentials also work
locally. **All pull requests receive no private-source token**, including same-repository PRs; without another authorized
credential the private-repository check fails as unverifiable, not as current. This metadata-only job does not run
private scenarios or publish their logs/artifacts.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@
"l10n": "node l10n/scripts/build.l10n.mjs",
"l10n:check": "node l10n/scripts/check.l10n.mjs",
"feed:check": "node scripts/check-package-feed.mjs",
"coda:check": "node scripts/check-coda-freshness.mjs",
"l10n:auto": "cross-env AZURE_TRANSLATOR_KEY= cross-env AZURE_TRANSLATOR_REGION= npx @vscode/l10n-dev generate-azure --outDir ./l10n ./l10n/bundle.l10n.json ./package.nls.json",
"l10n:export": "npx @vscode/l10n-dev generate-xlf ./l10n/bundle.l10n.json --outFile vscode-cosmosdb.xlf",
"l10n:import": "npx @vscode/l10n-dev import-xlf ./translations.xlf",
"fetch-skill": "node scripts/fetch-skill.mjs",
"fetch-coda": "node scripts/coda.mjs fetch",
"test:coda": "node scripts/coda.mjs test",
"test:coda-tools": "node --test scripts/coda.test.mjs",
"test:coda-tools": "node --test scripts/coda.test.mjs scripts/check-coda-freshness.test.mjs",
"pre-commit": "npm run build && npm run prettier-fix && npm run lint-fix && npm run l10n && npm run vitest",
"docker-up": "docker compose up -d",
"docker-down": "docker compose down",
Expand Down
136 changes: 136 additions & 0 deletions scripts/check-coda-freshness.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { spawnSync } from 'node:child_process';
import { appendFileSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { readCodaPin } from './coda.mjs';

const root = fileURLToPath(new URL('../', import.meta.url));

export function checkCodaFreshness(pin, { token = process.env.CODA_READ_TOKEN, temporaryRoot = tmpdir() } = {}) {
const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
if (token) {
// Scope authentication to this repository; never store the token in a URL, argument or Git config file.
const index = Number(env.GIT_CONFIG_COUNT ?? 0);
env.GIT_CONFIG_COUNT = String(index + 1);
env[`GIT_CONFIG_KEY_${index}`] = `http.${pin.repo}.extraheader`;
env[`GIT_CONFIG_VALUE_${index}`] = `Authorization: Basic ${Buffer.from(`:${token}`).toString('base64')}`;
}
function git(directory, args, allowMissingAncestor = false) {
const result = spawnSync(
'git',
[
'--no-pager',
'--git-dir',
directory,
'-c',
'credential.interactive=never',
'-c',
'core.hooksPath=',
...args,
],
{
encoding: 'utf8',
env,
windowsHide: true,
timeout: 180_000,
maxBuffer: 8 * 1024 * 1024,
},
);
if (allowMissingAncestor && !result.error && result.status === 1) {
return undefined;
}
if (result.error || result.status !== 0) {
throw new Error(
`CODA freshness Git operation failed (${args[0]}): ${result.error?.message ?? result.stderr.trim()}`,
);
}
return result.stdout.trim();
}
const directory = mkdtempSync(path.join(temporaryRoot, 'coda-freshness-'));
try {
git(directory, ['init', '--quiet', '--bare']);
const remote = git(directory, ['ls-remote', '--exit-code', pin.repo, pin.trackingRef]);
const lines = remote.split(/\r?\n/);
if (lines.length !== 1) {
throw new Error('CODA tracking ref must resolve to exactly one branch HEAD.');
}
const [head, ref] = lines[0].split(/\s+/);
if (!/^[a-f0-9]{40}$/.test(head) || ref !== pin.trackingRef) {
throw new Error('CODA returned an invalid tracking ref or HEAD.');
}
if (head === pin.commit) {
return { pin: pin.commit, head, ref, ahead: 0, behind: 0, relationship: 'equal' };
}
// Fetch immutable objects after resolving HEAD, without a working checkout or a shallow-history count.
git(directory, ['fetch', '--quiet', '--no-tags', '--filter=tree:0', pin.repo, pin.commit, head]);
const counts = git(directory, ['rev-list', '--left-right', '--count', `${pin.commit}...${head}`]).split(/\s+/);
const [behind, ahead] = counts.map(Number);
if (
counts.length !== 2 ||
!Number.isSafeInteger(ahead) ||
!Number.isSafeInteger(behind) ||
ahead < 0 ||
behind < 0
) {
throw new Error('CODA returned invalid ahead/behind counts.');
}
const ancestor = git(directory, ['merge-base', pin.commit, head], true);
const relationship = !ancestor ? 'unrelated' : behind === 0 ? 'ahead' : ahead === 0 ? 'behind' : 'diverged';
return { pin: pin.commit, head, ref, ahead, behind, relationship };
} finally {
rmSync(directory, { recursive: true, force: true });
}
}

export function formatFreshness(result) {
return [
`# CODA Freshness: ${result.relationship === 'equal' ? 'PASSED' : 'FAILED'}`,
'',
`Tracking ref: \`${result.ref}\``,
`Pinned commit: \`${result.pin}\``,
`Upstream HEAD: \`${result.head}\``,
'',
`Upstream HEAD is **${result.ahead} commits ahead** and **${result.behind} commits behind** the pin (${result.relationship}).`,
'',
'Read-only advisory: no pin, working checkout or cached conformance source was changed.',
'',
].join('\n');
}

export function main(args = process.argv.slice(2), configuredPin, env = process.env) {
if (args.length > 0) {
throw new Error('Usage: npm run coda:check');
}
const pin = configuredPin ?? readCodaPin(JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')));
const result = checkCodaFreshness(pin, { token: env.CODA_READ_TOKEN ?? '' });
const report = formatFreshness(result);
console.log(report);
if (env.GITHUB_STEP_SUMMARY) {
appendFileSync(env.GITHUB_STEP_SUMMARY, report);
}
if (result.relationship !== 'equal' && env.GITHUB_ACTIONS === 'true') {
console.error(
'::error::CODA branch HEAD differs from the pin. See the ahead/behind counts in the job summary.',
);
}
return result.relationship === 'equal' ? 0 : 1;
}

if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
try {
process.exitCode = main();
} catch (error) {
const message = `CODA freshness is unverifiable: ${error instanceof Error ? error.message : String(error)}`;
console.error(message);
if (process.env.GITHUB_STEP_SUMMARY) {
appendFileSync(process.env.GITHUB_STEP_SUMMARY, `# CODA Freshness: FAILED\n\n${message}\n`);
}
process.exitCode = 1;
}
}
Loading
Loading