Skip to content
Merged
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
194 changes: 194 additions & 0 deletions e2e/aws-logical-floci-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#!/usr/bin/env bash
# behold#100 (B·aws) — the AWS lane's acceptance run for chant's CC epic
# (chant#1198). AWS is the reference substrate for behold's three live views,
# so this asserts all three against one running estate, in one pass:
#
# 1. component status — painted from the RESOURCE ROLLUP (#98), not from
# CloudFormation stack status. This is the clause
# #100 exists to confirm: `stack` only exists on AWS,
# so if `stack` decided the colour, AWS would be the
# one substrate that never exercised the rollup #98
# added. Every row must carry `_liveStatus.resources`.
# 2. live overlay — `chant graph --live --overlay` (source-anchored,
# chant#821) classified per node, every declared node
# carrying a `_status`.
# 3. logical zoom — the nested architecture diagram (#63): the
# `region -> VPC -> subnet` network boxes containing
# component boxes containing headline resource cards.
#
# Like e2e/component-view-floci-e2e.sh (#59), this targets a real external
# project and its already-running Floci. It boots and installs NOTHING — that
# is the project's own lifecycle, not behold's — and fails fast with the
# command to run when a prerequisite is missing.
#
# The project defaults to loomster because it is the AWS estate already wired
# for this (real VPC/subnets, several components, a Floci to deploy onto).
# Point BEHOLD_E2E_PROJECT at the CC lane's canonical example to run the same
# assertions against that instead — nothing here is loomster-specific beyond
# the default path and the stack-name prefix probe.
set -euo pipefail
cd "$(dirname "$0")/.."

PROJECT="${BEHOLD_E2E_PROJECT:-${LOOMSTER_DIR:-$HOME/checkouts/intentius/loomster}}"
PORT="${BEHOLD_E2E_PORT:-4699}"
ENV="${BEHOLD_E2E_ENV:-local}"
ENDPOINT="${AWS_ENDPOINT_URL:-http://localhost:4566}"
STACK_PREFIX="${BEHOLD_E2E_STACK_PREFIX:-}"

echo "→ prerequisite: project checkout"
[ -d "$PROJECT" ] || { echo "✗ no project checkout at $PROJECT (set BEHOLD_E2E_PROJECT)"; exit 1; }
echo " $PROJECT"

echo "→ prerequisite: Floci reachable at $ENDPOINT"
if ! curl -sf "$ENDPOINT/_localstack/health" >/dev/null 2>&1; then
echo "✗ Floci isn't up at $ENDPOINT."
echo " Bring it up first (the project's own setup, not behold's):"
echo " cd $PROJECT && just local-up"
exit 1
fi

echo "→ prerequisite: the project's stacks are deployed"
QUERY="length(StackSummaries)"
[ -n "$STACK_PREFIX" ] && QUERY="length(StackSummaries[?starts_with(StackName, '$STACK_PREFIX')])"
STACK_COUNT=$(LOOM_ENV="$ENV" AWS_ENDPOINT_URL="$ENDPOINT" AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_REGION=us-east-1 \
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE \
--query "$QUERY" --output text 2>/dev/null || echo 0)
[ "$STACK_COUNT" -ge 1 ] || { echo "✗ no deployed stacks found on Floci — deploy the project first (\`just local-up\`)"; exit 1; }
echo " $STACK_COUNT stack(s) present"

echo "→ build behold"
npm run build --silent

echo "→ serve $PROJECT on :$PORT (env=$ENV)"
LOOM_ENV="$ENV" AWS_ENDPOINT_URL="$ENDPOINT" AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_REGION=us-east-1 \
node ./bin/behold.js serve "$PROJECT" --env "$ENV" --port "$PORT" >/tmp/behold-aws-logical-e2e.log 2>&1 &
PID=$!
trap 'kill "$PID" 2>/dev/null || true' EXIT

ready=""
for _ in $(seq 1 45); do
curl -sf "http://localhost:$PORT/healthz" >/dev/null 2>&1 && { ready=1; break; }
sleep 1
done
[ -n "$ready" ] || { echo "✗ behold did not come up"; sed -n '1,40p' /tmp/behold-aws-logical-e2e.log; exit 1; }

# ---------------------------------------------------------------- 1. status --
echo "→ (1/3) GET /api/graph?components=1&env=$ENV — component status on the #98 rollup source"
curl -sf "http://localhost:$PORT/api/graph?components=1&env=$ENV" >/tmp/behold-aws-logical-status.json
node -e '
const j = JSON.parse(require("node:fs").readFileSync("/tmp/behold-aws-logical-status.json", "utf8"));
if (j.error) { console.error("✗ api error:", j.error); process.exit(1); }
const { ir, meta } = j;
if (meta.mode !== "component-status") { console.error("✗ expected mode component-status, got", meta.mode); process.exit(1); }
if (!ir.nodes.length) { console.error("✗ no component nodes"); process.exit(1); }

const uncoloured = ir.nodes.filter((n) => !(n.attrs && n.attrs._status));
if (uncoloured.length) { console.error("✗", uncoloured.length, "component node(s) missing _status:", uncoloured.map((n) => n.id)); process.exit(1); }

// The #100 clause. chant#1300 emits `resources` for every component with
// live evidence, INCLUDING on AWS where a `stack` is also present. A row
// without it means either an older chant (below the 0.34 floor) or a status
// path that never gathered evidence — both make the paint unverifiable.
const noRollup = ir.nodes.filter((n) => !(n.attrs && n.attrs._liveStatus && n.attrs._liveStatus.resources));
if (noRollup.length) {
console.error("✗", noRollup.length, "component(s) carry no resource rollup:", noRollup.map((n) => n.id).join(", "));
console.error(" chant must be >= 0.34 (behold#98 / chant#1300) for the rollup to reach behold at all.");
process.exit(1);
}

// And the paint must actually be the rollup talking. A component whose
// resources are all present, sitting on a healthy stack, is `good` under
// both the old and new ordering — so the assertion that distinguishes them
// is the disagreement case: any component whose rollup is NOT all-present
// must not be painted `good` just because CloudFormation said CREATE_COMPLETE.
const lying = ir.nodes.filter((n) => {
const { _status: s, _liveStatus: l } = n.attrs;
const r = l.resources;
return s === "good" && r.total > 0 && r.present !== r.total;
});
if (lying.length) {
console.error("✗ painted good over an incomplete rollup — CFN status is still the source:");
for (const n of lying) console.error(" ", n.id, JSON.stringify(n.attrs._liveStatus.resources), "stack:", JSON.stringify(n.attrs._liveStatus.stack));
process.exit(1);
}

const shape = (n) => { const r = n.attrs._liveStatus.resources; return `${n.id} ${n.attrs._status} ${r.present}/${r.total}${r.unobserved ? ` (${r.unobserved} unread)` : ""}`; };
console.log(` ok: ${ir.nodes.length} components, all carrying a rollup`);
for (const n of ir.nodes) console.log(" ", shape(n));
'

# --------------------------------------------------------------- 2. overlay --
echo "→ (2/3) GET /api/overlay?env=$ENV — the source-anchored live overlay"
curl -sf "http://localhost:$PORT/api/overlay?env=$ENV" >/tmp/behold-aws-logical-overlay.json
node -e '
const j = JSON.parse(require("node:fs").readFileSync("/tmp/behold-aws-logical-overlay.json", "utf8"));
if (j.error) { console.error("✗ /api/overlay error:", j.error, j.remedy || ""); process.exit(1); }
const { ir, svg, meta } = j;
if (meta.mode !== "overlay") { console.error("✗ expected mode overlay, got", meta.mode); process.exit(1); }
if (!ir.nodes.length) { console.error("✗ overlay returned no nodes"); process.exit(1); }
if (!/<svg/.test(svg || "")) { console.error("✗ no svg rendered"); process.exit(1); }

// Every node chant classified carries `_status` — good/warn/accent/neutral/
// runtime (src/overlay.ts). A node with none means the join did not reach it.
const untagged = ir.nodes.filter((n) => !(n.attrs && n.attrs._status));
if (untagged.length) {
console.error("✗", untagged.length, "overlay node(s) carry no _status, e.g.", untagged.slice(0, 5).map((n) => `${n.id} (${n.kind})`).join(", "));
process.exit(1);
}
const byStatus = {};
for (const n of ir.nodes) byStatus[n.attrs._status] = (byStatus[n.attrs._status] || 0) + 1;
console.log(` ok: ${ir.nodes.length} nodes, ${ir.edges.length} edges,`, JSON.stringify(byStatus));
'

# --------------------------------------------------------------- 3. logical --
echo "→ (3/3) GET /api/overlay?logical=1&env=$ENV — the nested architecture diagram on live status"
curl -sf "http://localhost:$PORT/api/overlay?logical=1&env=$ENV" >/tmp/behold-aws-logical-arch.json
node -e '
const j = JSON.parse(require("node:fs").readFileSync("/tmp/behold-aws-logical-arch.json", "utf8"));
if (j.error) { console.error("✗ logical error:", j.error, j.remedy || ""); process.exit(1); }
const { ir, svg, byContainer, meta } = j;
if (meta.mode !== "logical") { console.error("✗ expected mode logical, got", meta.mode); process.exit(1); }
if (!byContainer) { console.error("✗ no byContainer in the response — behold is older than #100"); process.exit(1); }
if (!ir.nodes.length) { console.error("✗ no headline cards survived the projection"); process.exit(1); }
if (!/<svg/.test(svg || "")) { console.error("✗ no svg rendered"); process.exit(1); }

// Every surviving card must be placed. An unplaced card renders outside every
// box, which is the failure the nesting exists to prevent.
const placed = new Set(Object.values(byContainer).flat());
const orphans = ir.nodes.filter((n) => !placed.has(n.id));
if (orphans.length) { console.error("✗", orphans.length, "headline card(s) in no container:", orphans.map((n) => n.id).join(", ")); process.exit(1); }

// The nesting has to be genuinely nested — a VPC box holding a subnet box
// holding a component box holding cards. A flat map (every component hanging
// off the global lane) means containment resolution failed, which is exactly
// what the cross-stack bridge in logical.ts `enrichedRefs` is there to fix.
const containers = new Set(Object.keys(byContainer));
const nodeIds = new Set(ir.nodes.map((n) => n.id));
const depth = (id, seen = new Set()) => {
if (seen.has(id) || !byContainer[id]) return 0;
seen.add(id);
return 1 + Math.max(0, ...byContainer[id].map((c) => depth(c, seen)));
};
const roots = [...containers].filter((c) => !Object.values(byContainer).flat().includes(c));
const deepest = Math.max(0, ...roots.map((r) => depth(r)));
if (deepest < 2) {
console.error("✗ containment is flat (depth", deepest + ") — expected at least VPC > component > cards");
console.error(" byContainer:", JSON.stringify(byContainer, null, 2));
process.exit(1);
}

const vpcBoxes = [...containers].filter((c) => /\bVPC\b/.test(c));
const subnetBoxes = [...containers].filter((c) => /subnet/i.test(c));
if (!vpcBoxes.length) { console.error("✗ no VPC box in the nesting — network containment did not resolve"); process.exit(1); }

// The overlay statuses have to SURVIVE the projection — the logical lens over
// a live overlay is only worth anything if the cards keep their drift colour.
const coloured = ir.nodes.filter((n) => n.attrs && n.attrs._status).length;
if (!coloured) { console.error("✗ no headline card kept its live _status through the projection"); process.exit(1); }

console.log(` ok: ${ir.nodes.length} headline cards, ${ir.edges.length} contracted edges, nesting depth ${deepest}`);
console.log(` ${vpcBoxes.length} VPC box(es), ${subnetBoxes.length} subnet box(es), ${coloured}/${ir.nodes.length} cards carrying live status`);
for (const r of roots) console.log(" ", r, "->", byContainer[r].join(", "));
'

echo "✓ behold#100 passed — component status on the #98 rollup, live overlay, and the nested architecture diagram, all on one live AWS estate"
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ e2e:
# in loomster) — this never boots or installs loomster itself.
e2e-floci:
bash e2e/component-view-floci-e2e.sh

# behold#100 (B·aws, chant epic #1198): the AWS lane's acceptance run — component
# status painted from the #98 resource rollup (not CFN stack status), the live
# overlay, and the nested architecture diagram, all against one running estate.
# Needs a deployed AWS project and its Floci already up; boots neither.
# just e2e-aws-logical
# BEHOLD_E2E_PROJECT=/path/to/example just e2e-aws-logical
e2e-aws-logical:
bash e2e/aws-logical-floci-e2e.sh
81 changes: 73 additions & 8 deletions src/component-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,6 @@ describe("componentStatusColor — resource rollup (behold#98)", () => {
expect(componentStatusColor(row)).toBe("warn");
});

it("a stack still wins where a substrate has one — AWS is unchanged", () => {
const row = withRollup(
{ total: 3, present: 0, absent: 3, unobserved: 0 },
{ live: true, stack: { name: "app-prod", status: "CREATE_COMPLETE", healthy: true } },
);
expect(componentStatusColor(row)).toBe("good");
});

it("an empty rollup falls through rather than claiming anything", () => {
const row = withRollup({ total: 0, present: 0, absent: 0, unobserved: 0 }, { live: true });
expect(componentStatusColor(row)).toBe("good"); // the `live` tier
Expand All @@ -310,3 +302,76 @@ describe("componentStatusColor — resource rollup (behold#98)", () => {
});
});
});

// behold#100 — AWS is the reference lane, so it has to actually RUN on the
// rollup. Until now a present `stack` returned before the rollup was read, and
// AWS is the only substrate with a stack: the substrate #98 was verified
// against was the one substrate that never used it. The split now is that the
// rollup answers "is it there" and the stack answers "did the deploy go wrong",
// so a HEALTHY stack no longer overrules the resources and an UNHEALTHY one
// still decides (M2's loom-db case, unchanged).
describe("componentStatusColor — AWS reads the rollup too (behold#100)", () => {
const aws = (
resources: { total: number; present: number; absent: number; unobserved: number },
stack: { name: string; status?: string; healthy?: boolean },
) =>
({
component: "loom-backend",
env: "local",
reconciliation: "reconciled" as const,
detail: "recorded 2026-07-19T03:08:35.076Z (digest sha256:86bf5e3c…), live and consistent",
live: true,
stack,
resources,
}) as unknown as ComponentStatusRow;

const HEALTHY = { name: "loom-local-a-loom-backend", status: "CREATE_COMPLETE", healthy: true };
const ROLLBACK = { name: "loom-local-a-loom-db", status: "UPDATE_ROLLBACK_COMPLETE", healthy: false };
const IN_PROGRESS = { name: "loom-local-a-loom-frontend", status: "UPDATE_IN_PROGRESS", healthy: false };

it("healthy stack + every resource present -> good (unchanged)", () => {
expect(componentStatusColor(aws({ total: 3, present: 3, absent: 0, unobserved: 0 }, HEALTHY))).toBe("good");
});

it("healthy stack + nothing present -> neutral, NOT good", () => {
// A stack whose last operation succeeded but whose resources did not come
// back is not a green component. (On AWS today the rollup reads
// CloudFormation's own inventory, so the two rarely disagree this hard —
// see the #100 note in component-status.ts on what the colour does and
// does not claim.)
expect(componentStatusColor(aws({ total: 3, present: 0, absent: 3, unobserved: 0 }, HEALTHY))).toBe("neutral");
});

it("healthy stack + partly present -> warn, NOT good", () => {
expect(componentStatusColor(aws({ total: 3, present: 2, absent: 1, unobserved: 0 }, HEALTHY))).toBe("warn");
});

it("healthy stack + a hole -> accent, NOT good — chant could not read part of it", () => {
expect(componentStatusColor(aws({ total: 3, present: 2, absent: 0, unobserved: 1 }, HEALTHY))).toBe("accent");
});

it("a rollback stack still wins over a fully-present rollup — M2's loom-db proof case survives", () => {
expect(componentStatusColor(aws({ total: 3, present: 3, absent: 0, unobserved: 0 }, ROLLBACK))).toBe("warn");
});

it("a mid-deploy stack still wins over a fully-present rollup — in-flight explains any rollup shape under it", () => {
expect(componentStatusColor(aws({ total: 3, present: 3, absent: 0, unobserved: 0 }, IN_PROGRESS))).toBe("accent");
});

it("a mid-deploy stack outranks a half-built rollup rather than calling it drift", () => {
// Partial presence during a deploy is expected, not a broken component.
expect(componentStatusColor(aws({ total: 3, present: 1, absent: 2, unobserved: 0 }, IN_PROGRESS))).toBe("accent");
});

it("a healthy stack with no rollup still paints from the live boolean — an older chant is unaffected", () => {
const row = {
component: "loom-backend",
env: "local",
reconciliation: "reconciled" as const,
detail: "live and consistent",
live: true,
stack: HEALTHY,
} as unknown as ComponentStatusRow;
expect(componentStatusColor(row)).toBe("good");
});
});
Loading
Loading