mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-17 21:15:40 +02:00
* feat: add Plan Canvas - browser annotate-and-approve review for plan artifacts - scripts/plan-canvas.js CLI (open/await/end/stop/server; bin ecc-plan-canvas) - loopback server + ECC-styled chrome + annotation SDK + zero-dep markdown renderer - Approve/Request-changes verdicts wired to the /plan confirmation gate - plan-canvas skill, /plan-canvas command, SessionStart hook surfacing open reviews - shared scripts/lib/loopback-guard.js extracted from control-pane (API re-exported) - 121 new tests incl. full-workflow E2E; registered in manifests, catalog, registry Inspired by lavish-axi (https://github.com/kunchenguid/lavish-axi) by @kunchenguid; original ECC-native implementation, not a port. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor(plan-canvas): invoke via ecc-plan-canvas bin so the skill works from any project Skill/command referenced a cwd-relative `node scripts/plan-canvas.js`, unusable outside the ECC root. Switch to the ecc-plan-canvas bin (and $CLAUDE_PLUGIN_ROOT fallback) and align CLI next_step hints so an agent can run it as a skill in any repo. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(plan-canvas): render Mermaid diagrams + ship Codex cross-harness surface - markdown renderer emits <pre class="mermaid"> for ```mermaid blocks (source entity-escaped so the browser decodes it for the renderer while blocking injection) - artifact template loads a pinned Mermaid build only when a diagram is present, themed to ECC dark, securityLevel strict, graceful offline fallback to source (ECC_PLAN_CANVAS_MERMAID_URL overrides for a local mirror) - skill teaches Mermaid-for-diagrams and states the CLI+JSON loop is harness-agnostic - add .agents/skills/plan-canvas (Codex) with agents/openai.yaml interface manifest - register in install-modules workflow-quality paths; docs updated Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(plan-canvas): add demo screenshot Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(ci): sync yarn.lock with new bin; add contributor checklist - yarn.lock records the ecc-plan-canvas bin so Yarn hardened-mode install no longer wants to modify the lockfile on public PRs - PR template + CONTRIBUTING gain a pre-push checklist covering the lockfile trap and the full skill/command/CLI registration surfaces Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Haley Chen <2022hachen@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
123 lines
4.0 KiB
JavaScript
123 lines
4.0 KiB
JavaScript
/**
|
|
* Tests for scripts/lib/loopback-guard.js
|
|
*
|
|
* Run with: node tests/lib/loopback-guard.test.js
|
|
*/
|
|
|
|
const assert = require('assert');
|
|
|
|
const {
|
|
LOOPBACK_HOSTNAMES,
|
|
buildAllowedHostnames,
|
|
isAllowedHostHeader,
|
|
isAllowedOrigin,
|
|
parseHostHeader
|
|
} = require('../../scripts/lib/loopback-guard');
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
return true;
|
|
} catch (err) {
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` Error: ${err.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function runTests() {
|
|
console.log('\n=== Testing loopback-guard.js ===\n');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
console.log('parseHostHeader:');
|
|
|
|
if (test('strips port from hostname', () => {
|
|
assert.strictEqual(parseHostHeader('127.0.0.1:4517'), '127.0.0.1');
|
|
assert.strictEqual(parseHostHeader('localhost:80'), 'localhost');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('handles bare hostnames', () => {
|
|
assert.strictEqual(parseHostHeader('localhost'), 'localhost');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('lowercases hostnames', () => {
|
|
assert.strictEqual(parseHostHeader('LocalHost:3000'), 'localhost');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('keeps bracketed IPv6 hosts intact', () => {
|
|
assert.strictEqual(parseHostHeader('[::1]:4517'), '[::1]');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('returns null for missing or malformed values', () => {
|
|
assert.strictEqual(parseHostHeader(null), null);
|
|
assert.strictEqual(parseHostHeader(undefined), null);
|
|
assert.strictEqual(parseHostHeader(''), null);
|
|
assert.strictEqual(parseHostHeader(' '), null);
|
|
assert.strictEqual(parseHostHeader(42), null);
|
|
assert.strictEqual(parseHostHeader('bad:host:extra'), null);
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nbuildAllowedHostnames:');
|
|
|
|
if (test('always includes loopback names', () => {
|
|
const set = buildAllowedHostnames(null);
|
|
for (const name of LOOPBACK_HOSTNAMES) assert.ok(set.has(name));
|
|
})) passed++; else failed++;
|
|
|
|
if (test('adds the configured host lowercased', () => {
|
|
const set = buildAllowedHostnames('MyBox.Local');
|
|
assert.ok(set.has('mybox.local'));
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nisAllowedHostHeader:');
|
|
|
|
const allowed = buildAllowedHostnames('127.0.0.1');
|
|
|
|
if (test('accepts loopback host headers', () => {
|
|
assert.strictEqual(isAllowedHostHeader('127.0.0.1:4517', allowed), true);
|
|
assert.strictEqual(isAllowedHostHeader('localhost:4517', allowed), true);
|
|
assert.strictEqual(isAllowedHostHeader('[::1]:4517', allowed), true);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('rejects DNS-rebinding style hostnames', () => {
|
|
assert.strictEqual(isAllowedHostHeader('evil.example.com', allowed), false);
|
|
assert.strictEqual(isAllowedHostHeader('127.0.0.1.evil.example.com', allowed), false);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('rejects missing host header', () => {
|
|
assert.strictEqual(isAllowedHostHeader(undefined, allowed), false);
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nisAllowedOrigin:');
|
|
|
|
if (test('absent origin is allowed (same-origin nav, CLI)', () => {
|
|
assert.strictEqual(isAllowedOrigin(undefined, allowed), true);
|
|
assert.strictEqual(isAllowedOrigin(null, allowed), true);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('loopback origins are allowed', () => {
|
|
assert.strictEqual(isAllowedOrigin('http://127.0.0.1:4517', allowed), true);
|
|
assert.strictEqual(isAllowedOrigin('http://localhost:4517', allowed), true);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('cross-site origins are rejected', () => {
|
|
assert.strictEqual(isAllowedOrigin('https://evil.example.com', allowed), false);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('malformed origins are rejected', () => {
|
|
assert.strictEqual(isAllowedOrigin('not a url', allowed), false);
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\n' + '='.repeat(40));
|
|
console.log(`Passed: ${passed}`);
|
|
console.log(`Failed: ${failed}`);
|
|
console.log('='.repeat(40));
|
|
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
}
|
|
|
|
runTests();
|