Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(timeline): reject duplicate lane identities

杨嘉伟c5830aa693c7
diff --git a/archify/renderers/timeline/render-timeline.mjs b/archify/renderers/timeline/render-timeline.mjs
index 9bff3822..9d1927ad 100644
--- a/archify/renderers/timeline/render-timeline.mjs
+++ b/archify/renderers/timeline/render-timeline.mjs
@@ -84,7 +84,12 @@ const timezone = tl.meta.timezone || 'UTC';
fail('timeline/invalid-timezone', `meta.timezone "${timezone}" is not a recognised IANA time zone.`,
{ path: '/meta/timezone' }, { timezone }, ['Use an IANA zone such as "UTC", "Europe/Berlin", or "Asia/Shanghai".']);
}
- const laneIds = new Set(asArray(tl.lanes).map((lane) => lane.id));
+ const laneIds = new Set();
+ for (const [index, lane] of asArray(tl.lanes).entries()) {
+ if (laneIds.has(lane.id)) fail('timeline/duplicate-lane-id', `Lane id "${lane.id}" is declared twice.`,
+ { path: `/lanes/${index}/id` }, { id: lane.id }, ['Give every lane a unique id and update its event references.']);
+ laneIds.add(lane.id);
+ }
const seen = new Set();
for (const [index, event] of asArray(tl.events).entries()) {
if (seen.has(event.id)) fail('timeline/duplicate-id', `Event id "${event.id}" is declared twice.`, { path: `/events/${index}/id` }, { id: event.id }, ['Give every event a unique id.']);
diff --git a/test/timeline-rendering.test.mjs b/test/timeline-rendering.test.mjs
index 6ae0c832..01aaa5d0 100644
--- a/test/timeline-rendering.test.mjs
+++ b/test/timeline-rendering.test.mjs
@@ -38,6 +38,16 @@ test('timeline: both examples render and pass the showcase artifact checks', ()
}
});
+test('timeline: duplicate lane IDs fail before visual and accessible ownership diverge', () => {
+ const diagram = clone(small);
+ diagram.lanes.push({ ...diagram.lanes[0], label: 'Conflicting lane' });
+ const result = run(diagram);
+ assert.equal(result.status, 1);
+ assert.match(result.stderr, /timeline\/duplicate-lane-id/);
+ assert.match(result.stderr, /Give every lane a unique id/);
+ assert.equal(fs.existsSync(result.output), false);
+});
+
test('timeline: position is linear in time on one shared axis across lanes', () => {
const report = layoutOf(small);
assert.equal(report.breaks.length, 0);