mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-24 00:35:31 +00:00
Resolve both sides of the source_doc containment check with fs.realpathSync.native (falling back to fs.realpathSync). With the JS realpath, a repo root reached through a Windows 8.3 short name stays in short form while an in-repo symlink whose target uses the long-path form resolves to the long form, so a legitimate in-repo doc was reported as "resolves outside repository root". Escapes outside the repo are still rejected. Adds a cross-platform regression test that models differing JS and native realpath results: in-repo docs are accepted through a short-form root and an outside target is still rejected. It fails on the previous implementation. Not required for the #3882 Windows CI fix; kept as a separate commit so it can be taken or dropped on its own.
346 lines
13 KiB
JavaScript
346 lines
13 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const { execFileSync } = require('child_process');
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const {
|
|
ADAPTER_RECORDS,
|
|
MATRIX_BLOCK_END,
|
|
MATRIX_BLOCK_START,
|
|
extractMatrixBlock,
|
|
renderMarkdownTable,
|
|
validateAdapterRecords,
|
|
validateDocumentation,
|
|
validateSourceDocs,
|
|
} = require('../../scripts/lib/harness-adapter-compliance');
|
|
|
|
const repoRoot = path.resolve(__dirname, '..', '..');
|
|
const scriptPath = path.join(repoRoot, 'scripts', 'harness-adapter-compliance.js');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
passed++;
|
|
} catch (error) {
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` Error: ${error.message}`);
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
function read(relativePath) {
|
|
return fs.readFileSync(path.join(repoRoot, relativePath), 'utf8');
|
|
}
|
|
|
|
console.log('\n=== Testing harness adapter compliance docs ===\n');
|
|
|
|
test('adapter compliance matrix covers the required harness surfaces', () => {
|
|
const source = read('docs/architecture/harness-adapter-compliance.md');
|
|
for (const harness of [
|
|
'Claude Code',
|
|
'Codex',
|
|
'Grok Build',
|
|
'OpenCode',
|
|
'Pi',
|
|
'Cursor',
|
|
'Gemini',
|
|
'Zed',
|
|
'dmux',
|
|
'DeepSeek Harness',
|
|
'Antigravity',
|
|
'Qwen Code',
|
|
'GitHub Copilot',
|
|
'Hermes',
|
|
'Orca',
|
|
'Superset',
|
|
'Ghast',
|
|
'Terminal-only'
|
|
]) {
|
|
assert.ok(source.includes(harness), `Expected matrix to include ${harness}`);
|
|
}
|
|
});
|
|
|
|
test('shipped first-party install targets are represented as Adapter-backed records', () => {
|
|
const expectedTargets = [
|
|
['antigravity', '`./install.sh --profile minimal --target antigravity`', 'docs/ANTIGRAVITY-GUIDE.md'],
|
|
['qwen', '`./install.sh --target qwen --profile minimal`', 'docs/QWEN-GUIDE.md'],
|
|
['copilot', '`./install.sh --profile minimal --target copilot`', 'scripts/lib/install-targets/copilot-project.js'],
|
|
['hermes', '`./install.sh --profile minimal --target hermes`', 'docs/HERMES-HOOKS.md'],
|
|
];
|
|
|
|
for (const [id, onramp, sourceDoc] of expectedTargets) {
|
|
const record = ADAPTER_RECORDS.find(entry => entry.id === id);
|
|
assert.ok(record, `Expected adapter record for ${id}`);
|
|
assert.strictEqual(record.state, 'Adapter-backed', `${id} should be Adapter-backed`);
|
|
assert.ok(record.install_or_onramp.includes(onramp), `${id} should include installer onramp ${onramp}`);
|
|
assert.ok(record.source_docs.includes(sourceDoc), `${id} should reference ${sourceDoc}`);
|
|
}
|
|
});
|
|
|
|
test('adapter compliance source data validates required evidence fields', () => {
|
|
assert.deepStrictEqual(validateAdapterRecords(), []);
|
|
|
|
const zedRecord = ADAPTER_RECORDS.find(record => record.id === 'zed');
|
|
assert.ok(zedRecord, 'Expected Zed adapter record');
|
|
assert.strictEqual(zedRecord.state, 'Adapter-backed');
|
|
assert.ok(
|
|
zedRecord.install_or_onramp.includes('`./install.sh --profile minimal --target zed`'),
|
|
'Expected Zed installer onramp'
|
|
);
|
|
|
|
for (const record of ADAPTER_RECORDS) {
|
|
assert.ok(record.install_or_onramp.length > 0, `${record.id} needs an install or onramp`);
|
|
assert.ok(record.verification_commands.length > 0, `${record.id} needs verification commands`);
|
|
assert.ok(record.risk_notes.length > 0, `${record.id} needs risk notes`);
|
|
assert.ok(record.source_docs.length > 0, `${record.id} needs source docs`);
|
|
}
|
|
});
|
|
|
|
test('adapter compliance matrix is generated from source data', () => {
|
|
const source = read('docs/architecture/harness-adapter-compliance.md');
|
|
assert.strictEqual(extractMatrixBlock(source), renderMarkdownTable());
|
|
});
|
|
|
|
test('adapter compliance matrix extraction tolerates Windows line endings', () => {
|
|
const source = read('docs/architecture/harness-adapter-compliance.md')
|
|
.replace(/\r\n/g, '\n')
|
|
.replace(/\n/g, '\r\n');
|
|
assert.strictEqual(extractMatrixBlock(source), renderMarkdownTable());
|
|
});
|
|
|
|
test('adapter compliance matrix includes the required evidence columns', () => {
|
|
const source = read('docs/architecture/harness-adapter-compliance.md');
|
|
for (const heading of [
|
|
'Supported assets',
|
|
'Unsupported or different surfaces',
|
|
'Install or onramp',
|
|
'Verification command',
|
|
'Risk notes'
|
|
]) {
|
|
assert.ok(source.includes(heading), `Expected matrix to include ${heading}`);
|
|
}
|
|
});
|
|
|
|
test('scorecard onramp names the local verification commands', () => {
|
|
const source = read('docs/architecture/harness-adapter-compliance.md');
|
|
for (const command of [
|
|
'npm run harness:adapters -- --check',
|
|
'npm run harness:audit -- --format json',
|
|
'npm run observability:ready',
|
|
'node scripts/session-inspect.js --list-adapters',
|
|
'node scripts/loop-status.js --json --write-dir .ecc/loop-status'
|
|
]) {
|
|
assert.ok(source.includes(command), `Expected onramp to include ${command}`);
|
|
}
|
|
});
|
|
|
|
test('adapter compliance CLI check passes against the committed doc', () => {
|
|
const output = execFileSync('node', [scriptPath, '--check'], {
|
|
cwd: repoRoot,
|
|
encoding: 'utf8',
|
|
});
|
|
|
|
assert.ok(output.includes('Harness Adapter Compliance: PASS'));
|
|
assert.ok(output.includes(`Adapters: ${ADAPTER_RECORDS.length}`));
|
|
});
|
|
|
|
test('adapter compliance CLI emits machine-readable scorecard data', () => {
|
|
const output = execFileSync('node', [scriptPath, '--format=json'], {
|
|
cwd: repoRoot,
|
|
encoding: 'utf8',
|
|
});
|
|
const parsed = JSON.parse(output);
|
|
|
|
assert.strictEqual(parsed.schema_version, 'ecc.harness-adapter-compliance.v1');
|
|
assert.strictEqual(parsed.valid, true);
|
|
assert.strictEqual(parsed.adapter_count, ADAPTER_RECORDS.length);
|
|
assert.ok(parsed.adapters.some(record => record.id === 'terminal-only'));
|
|
});
|
|
|
|
test('cross-harness architecture links to the adapter compliance matrix', () => {
|
|
const source = read('docs/architecture/cross-harness.md');
|
|
assert.ok(source.includes('harness-adapter-compliance.md'));
|
|
});
|
|
|
|
test('GA roadmap records the matrix and validator as current evidence', () => {
|
|
const source = read('docs/ECC-2.0-GA-ROADMAP.md');
|
|
assert.ok(source.includes('docs/architecture/harness-adapter-compliance.md'));
|
|
assert.ok(source.includes('npm run harness:adapters -- --check'));
|
|
assert.ok(source.includes('scripts/lib/harness-adapter-compliance.js'));
|
|
});
|
|
|
|
test('every committed adapter source_doc exists inside the repository root', () => {
|
|
assert.deepStrictEqual(validateSourceDocs(ADAPTER_RECORDS, { repoRoot }), []);
|
|
});
|
|
|
|
test('validateSourceDocs and validateDocumentation accept leading-dot segments and reject missing or traversal paths', () => {
|
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-compliance-'));
|
|
|
|
try {
|
|
const validDoc = path.join(tempRoot, 'docs', 'GUIDE.md');
|
|
const doubleDotSegmentDoc = path.join(tempRoot, '..notes', 'GUIDE.md');
|
|
fs.mkdirSync(path.dirname(validDoc), { recursive: true });
|
|
fs.mkdirSync(path.dirname(doubleDotSegmentDoc), { recursive: true });
|
|
fs.writeFileSync(validDoc, '# Guide\n');
|
|
fs.writeFileSync(doubleDotSegmentDoc, '# Notes\n');
|
|
|
|
const baseRecord = {
|
|
id: 'sample',
|
|
harness: 'Sample',
|
|
state: 'Adapter-backed',
|
|
supported_assets: ['skills'],
|
|
unsupported_surfaces: ['hooks'],
|
|
install_or_onramp: ['`./install.sh --target sample`'],
|
|
verification_commands: ['`npm test`'],
|
|
risk_notes: ['None'],
|
|
last_verified_at: '2026-10-30',
|
|
owner: 'ECC maintainers',
|
|
source_docs: ['docs/GUIDE.md', '..notes/GUIDE.md'],
|
|
};
|
|
|
|
assert.deepStrictEqual(validateSourceDocs([baseRecord], { repoRoot: tempRoot }), []);
|
|
|
|
const missingErrors = validateSourceDocs(
|
|
[{ ...baseRecord, source_docs: ['docs/MISSING.md'] }],
|
|
{ repoRoot: tempRoot }
|
|
);
|
|
assert.strictEqual(missingErrors.length, 1);
|
|
assert.match(missingErrors[0], /sample: missing source_doc docs\/MISSING\.md/);
|
|
|
|
for (const unsafePath of ['..', '../outside.md', 'docs/../../outside.md', '/etc/passwd', 'C:/outside.md']) {
|
|
const traversalErrors = validateSourceDocs(
|
|
[{ ...baseRecord, source_docs: [unsafePath] }],
|
|
{ repoRoot: tempRoot }
|
|
);
|
|
assert.strictEqual(traversalErrors.length, 1, `Expected error for ${unsafePath}`);
|
|
assert.match(traversalErrors[0], /must be a repo-relative path without '\.\.'/);
|
|
}
|
|
|
|
const matrixDoc = path.join(tempRoot, 'docs', 'architecture', 'harness-adapter-compliance.md');
|
|
fs.mkdirSync(path.dirname(matrixDoc), { recursive: true });
|
|
const badRecords = [{ ...baseRecord, source_docs: ['docs/MISSING.md'] }];
|
|
fs.writeFileSync(
|
|
matrixDoc,
|
|
`${MATRIX_BLOCK_START}\n${renderMarkdownTable(badRecords)}\n${MATRIX_BLOCK_END}\n`
|
|
);
|
|
|
|
const docErrors = validateDocumentation({
|
|
repoRoot: tempRoot,
|
|
docPath: matrixDoc,
|
|
records: badRecords,
|
|
checkSourceDocs: true,
|
|
});
|
|
assert.strictEqual(docErrors.length, 1);
|
|
assert.match(docErrors[0], /sample: missing source_doc docs\/MISSING\.md/);
|
|
} finally {
|
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test('validateSourceDocs rejects a symlinked source_doc escaping the repository root', () => {
|
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-symlink-'));
|
|
const outsideRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-outside-'));
|
|
|
|
try {
|
|
fs.mkdirSync(path.join(tempRoot, 'docs'), { recursive: true });
|
|
const outsideFile = path.join(outsideRoot, 'secret.md');
|
|
fs.writeFileSync(outsideFile, 'outside\n');
|
|
const symlinkDoc = path.join(tempRoot, 'docs', 'escaped-link.md');
|
|
|
|
try {
|
|
fs.symlinkSync(outsideFile, symlinkDoc, 'file');
|
|
} catch (error) {
|
|
if (process.platform === 'win32' && error.code === 'EPERM') {
|
|
console.log(' SKIP symbolic-link fixture: Windows privilege unavailable');
|
|
return;
|
|
}
|
|
throw error;
|
|
}
|
|
|
|
const symlinkErrors = validateSourceDocs(
|
|
[{
|
|
id: 'sample',
|
|
harness: 'Sample',
|
|
state: 'Adapter-backed',
|
|
supported_assets: ['skills'],
|
|
unsupported_surfaces: ['hooks'],
|
|
install_or_onramp: ['`./install.sh --target sample`'],
|
|
verification_commands: ['`npm test`'],
|
|
risk_notes: ['None'],
|
|
last_verified_at: '2026-10-30',
|
|
owner: 'ECC maintainers',
|
|
source_docs: ['docs/escaped-link.md'],
|
|
}],
|
|
{ repoRoot: tempRoot }
|
|
);
|
|
assert.strictEqual(symlinkErrors.length, 1);
|
|
assert.match(symlinkErrors[0], /resolves outside repository root/);
|
|
} finally {
|
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
fs.rmSync(outsideRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test('validateSourceDocs canonicalizes the root and source_docs with the native realpath', () => {
|
|
// Models Windows 8.3 aliasing without needing symlink privileges: the JS
|
|
// realpath keeps the root's short form (e.g. RUNNER~1) while an in-repo
|
|
// link resolves to a long-form target; the native realpath returns the
|
|
// long form for both. Before the fix, both in-repo docs were reported as
|
|
// outside the repository root.
|
|
const tempRoot = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-native-')));
|
|
const outsideRoot = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-adapter-native-outside-')));
|
|
const shortRoot = path.join(path.dirname(tempRoot), 'ECC-AD~1');
|
|
const realDoc = path.join(tempRoot, 'docs', 'real.md');
|
|
const linkDoc = path.join(tempRoot, 'docs', 'link.md');
|
|
const outsideDoc = path.join(tempRoot, 'docs', 'outside.md');
|
|
const outsideFile = path.join(outsideRoot, 'secret.md');
|
|
const originalRealpathSync = fs.realpathSync;
|
|
|
|
try {
|
|
fs.mkdirSync(path.join(tempRoot, 'docs'), { recursive: true });
|
|
for (const file of [realDoc, linkDoc, outsideDoc, outsideFile]) {
|
|
fs.writeFileSync(file, 'doc\n');
|
|
}
|
|
const linkTargets = new Map([[linkDoc, realDoc], [outsideDoc, outsideFile]]);
|
|
const nativeRealpath = value => linkTargets.get(path.resolve(value)) || path.resolve(value);
|
|
const jsRealpath = value => (path.resolve(value) === tempRoot ? shortRoot : nativeRealpath(value));
|
|
fs.realpathSync = Object.assign(jsRealpath, { native: nativeRealpath });
|
|
|
|
const errors = validateSourceDocs(
|
|
[{
|
|
id: 'sample',
|
|
harness: 'Sample',
|
|
state: 'Adapter-backed',
|
|
supported_assets: ['skills'],
|
|
unsupported_surfaces: ['hooks'],
|
|
install_or_onramp: ['`./install.sh --target sample`'],
|
|
verification_commands: ['`npm test`'],
|
|
risk_notes: ['None'],
|
|
last_verified_at: '2026-10-30',
|
|
owner: 'ECC maintainers',
|
|
source_docs: ['docs/real.md', 'docs/link.md', 'docs/outside.md'],
|
|
}],
|
|
{ repoRoot: tempRoot }
|
|
);
|
|
assert.strictEqual(errors.length, 1, errors.join('\n'));
|
|
assert.match(errors[0], /docs\/outside\.md resolves outside repository root/);
|
|
} finally {
|
|
fs.realpathSync = originalRealpathSync;
|
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
fs.rmSync(outsideRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
if (failed > 0) {
|
|
console.log(`\nFailed: ${failed}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`\nPassed: ${passed}`);
|