dsforge-harness 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dsforge-harness might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "dsforge-harness",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Verified design→design-system→code harness: a functional spec becomes Figma mockups, a token-bound design system, and token-faithful code, with automated check gates and two human review gates. Ships as a Claude Code plugin/skill.",
5
5
  "bin": { "dsforge": "bin/dsforge.js" },
6
+ "scripts": { "test": "node plugins/dsforge/skills/dsforge/validators/test/check-layout.test.js" },
6
7
  "files": ["bin/", "plugins/", "templates/", "README.md"],
7
8
  "keywords": ["design-to-code", "design-system", "figma", "design-tokens", "verification", "claude-code", "claude", "skill"],
8
9
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsforge",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Verified design→design-system→code harness: a functional spec becomes Figma mockups, a token-bound design system, and token-faithful code, with automated check gates (DS audit, mockup-vs-spec, code-vs-DS) and two human review gates.",
5
5
  "author": { "name": "jsiksn" },
6
6
  "homepage": "https://github.com/jsiksn/dsforge",
@@ -16,7 +16,7 @@ const CFG = {
16
16
  spacingMax: 64, // largest spacing token (px); largeGap advisory = gap > spacingMax*3
17
17
  overlayRe: '(^|[ _-])(action-menu|context-menu|row-action-menu|dropdown|popover|tooltip|overlay|modal|toast)',
18
18
  };
19
- figma.skipInvisibleInstanceChildren = false; // traverse instance interiors (label clipping lives there too)
19
+ figma.skipInvisibleInstanceChildren = true; // skip hidden interior layers — DS components park hidden internals off-frame (false outOfFrame); visible TEXT inside instances is still traversed (label clipping lives there too)
20
20
  const TOL = 2;
21
21
  const ov = new RegExp(CFG.overlayRe, 'i');
22
22
  const isOverlay = (n) => ov.test(n.name || '') || n.layoutPositioning === 'ABSOLUTE';
@@ -24,19 +24,26 @@ const bb = (n) => n.absoluteBoundingBox;
24
24
  const exceeds = (c, p) => c.x < p.x - TOL || c.y < p.y - TOL || (c.x + c.width) > (p.x + p.width) + TOL || (c.y + c.height) > (p.y + p.height) + TOL;
25
25
  const inter = (a, b) => { const ix = Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)); const iy = Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y)); return ix > TOL && iy > TOL ? ix * iy : 0; };
26
26
  function inInstance(n) { let p = n.parent; while (p) { if (p.type === 'INSTANCE') return true; p = p.parent; } return false; }
27
+ // hidden self, or any hidden ancestor up to (and incl.) the screen frame — not a rendered defect, so excluded from textClip/outOfFrame
28
+ function hidden(n) { let p = n; while (p) { if (p.visible === false) return true; if (p.id === CFG.screenFrameId) break; p = p.parent; } return false; }
27
29
 
28
30
  const screen = await figma.getNodeByIdAsync(CFG.screenFrameId);
29
31
  const all = screen.findAll(() => true);
30
32
  const hardFails = [], advisories = [];
31
33
 
32
- // textClip / outOfFrame — any node (incl. instance interiors) whose bbox exceeds its parent's bbox
34
+ // textClip / outOfFrame — VISIBLE nodes whose bbox exceeds their parent's. skipInvisibleInstanceChildren=true already
35
+ // drops hidden instance interiors; hidden() also drops authored-hidden nodes (and anything under a hidden ancestor).
36
+ // Inside an instance we only flag textClip of visible TEXT — interior non-text layout is the DS's responsibility
37
+ // (audited by check1), so a visible interior frame extending past its parent is not an outOfFrame here.
33
38
  for (const n of all) {
34
39
  const p = n.parent; if (!p || !('absoluteBoundingBox' in p)) continue;
40
+ if (isOverlay(n) || hidden(n)) continue;
35
41
  const cb = bb(n), pb = bb(p); if (!cb || !pb) continue;
36
- if (isOverlay(n)) continue;
37
- if (exceeds(cb, pb)) hardFails.push({ type: n.type === 'TEXT' ? 'textClip' : 'outOfFrame', node: n.name, id: n.id, chars: n.type === 'TEXT' ? n.characters : undefined });
42
+ if (!exceeds(cb, pb)) continue;
43
+ if (inInstance(n) && n.type !== 'TEXT') continue;
44
+ hardFails.push({ type: n.type === 'TEXT' ? 'textClip' : 'outOfFrame', node: n.name, id: n.id, chars: n.type === 'TEXT' ? n.characters : undefined });
38
45
  }
39
- for (const n of all) { if (n.type === 'TEXT' && n.textTruncation === 'ENDING') hardFails.push({ type: 'textTruncateSetting', node: n.name, id: n.id, chars: n.characters }); }
46
+ for (const n of all) { if (n.type === 'TEXT' && !hidden(n) && n.textTruncation === 'ENDING') hardFails.push({ type: 'textTruncateSetting', node: n.name, id: n.id, chars: n.characters }); }
40
47
 
41
48
  // authored-only structural checks (instance internals are the DS's responsibility, audited by check1)
42
49
  const authored = all.filter((n) => !inInstance(n));
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Regression test for check-layout.js (node, no Figma needed).
3
+ * node validators/test/check-layout.test.js
4
+ *
5
+ * check-layout.js is a body executed inside Figma via use_figma; this harness mocks the slice of the
6
+ * Plugin API it touches (figma.getNodeByIdAsync, node.findAll honoring skipInvisibleInstanceChildren,
7
+ * absoluteBoundingBox, visible, children/parent), runs the REAL shipped body, and asserts hardFails.
8
+ *
9
+ * FIXTURE A — the bug being fixed: a DS-component instance parks hidden internal layers OFF the frame
10
+ * (side-nav collapsed panel, pagination overflow). They are invisible and not rendered. Pre-fix the
11
+ * pass ran with skipInvisibleInstanceChildren=false and had no inInstance/hidden guard, so each such
12
+ * layer became a false outOfFrame (the Model Management A/B frames each produced ~70 of these).
13
+ * Post-fix: hardFails MUST be 0.
14
+ * FIXTURE B — guards against over-correction: real visible breakage is still caught (an authored clipped
15
+ * title + a clipped VISIBLE label inside an instance), while a VISIBLE non-text interior layer that
16
+ * extends past its parent is correctly ignored (DS internals are check1's job).
17
+ */
18
+ 'use strict';
19
+ const fs = require('fs');
20
+ const path = require('path');
21
+
22
+ const SRC = path.join(__dirname, '..', 'check-layout.js');
23
+
24
+ // ---- minimal Figma Plugin API mock ----------------------------------------
25
+ function buildFigma(rootSpec) {
26
+ const figma = { skipInvisibleInstanceChildren: false };
27
+
28
+ function make(spec, parent) {
29
+ const n = {
30
+ id: spec.id,
31
+ name: spec.name,
32
+ type: spec.type,
33
+ visible: spec.visible !== false, // default visible
34
+ absoluteBoundingBox: spec.bbox || null,
35
+ layoutMode: spec.layoutMode || 'NONE',
36
+ layoutPositioning: spec.layoutPositioning || 'AUTO',
37
+ layoutSizingHorizontal: spec.layoutSizingHorizontal || 'FIXED',
38
+ layoutSizingVertical: spec.layoutSizingVertical || 'FIXED',
39
+ fills: spec.fills !== undefined ? spec.fills : [{ type: 'SOLID' }],
40
+ width: spec.bbox ? spec.bbox.width : 0,
41
+ height: spec.bbox ? spec.bbox.height : 0,
42
+ textTruncation: spec.textTruncation || 'DISABLED',
43
+ characters: spec.characters,
44
+ parent: parent || null,
45
+ children: [],
46
+ };
47
+ n.children = (spec.children || []).map((c) => make(c, n));
48
+ // findAll over DESCENDANTS only, honoring skipInvisibleInstanceChildren (hidden nodes *inside
49
+ // instances* and their subtrees are skipped; authored hidden nodes are still returned).
50
+ n.findAll = function (pred) {
51
+ const out = [];
52
+ const skip = figma.skipInvisibleInstanceChildren;
53
+ const visit = (node, insideInstance) => {
54
+ for (const c of node.children) {
55
+ const childInside = insideInstance || node.type === 'INSTANCE';
56
+ if (skip && childInside && c.visible === false) continue;
57
+ if (pred(c)) out.push(c);
58
+ visit(c, childInside);
59
+ }
60
+ };
61
+ visit(this, false);
62
+ return out;
63
+ };
64
+ return n;
65
+ }
66
+
67
+ const root = make(rootSpec, null);
68
+ const index = {};
69
+ (function idx(n) { index[n.id] = n; n.children.forEach(idx); })(root);
70
+ figma.getNodeByIdAsync = (id) => Promise.resolve(index[id] || null);
71
+ return figma;
72
+ }
73
+
74
+ async function runCheckLayout(figma) {
75
+ const body = fs.readFileSync(SRC, 'utf8');
76
+ // body uses top-level await + a trailing `return {...}`; wrap as an async fn (no template literal,
77
+ // so any ${...}/backticks in the source stay inert).
78
+ const factory = new Function('figma', 'return (async function () {\n' + body + '\n})();');
79
+ return factory(figma);
80
+ }
81
+
82
+ // ---- fixtures --------------------------------------------------------------
83
+ // Screen id MUST be '0:0' (CFG.screenFrameId in check-layout.js).
84
+ const fixtureA = {
85
+ id: '0:0', name: 'Model Management', type: 'FRAME', layoutMode: 'VERTICAL', bbox: { x: 0, y: 0, width: 1440, height: 900 },
86
+ children: [
87
+ { id: 'A:nav', name: 'Model Management/side-nav', type: 'INSTANCE', bbox: { x: 0, y: 0, width: 240, height: 900 },
88
+ children: [
89
+ { id: 'A:navitems', name: 'nav-items', type: 'FRAME', layoutMode: 'VERTICAL', bbox: { x: 0, y: 0, width: 240, height: 400 },
90
+ children: [
91
+ // hidden internal panel parked far off-frame — the exact false-positive source
92
+ { id: 'A:collapsed', name: 'collapsed-panel', type: 'FRAME', visible: false, layoutMode: 'VERTICAL', bbox: { x: -560, y: -560, width: 200, height: 200 },
93
+ children: [ { id: 'A:more', name: 'More options', type: 'TEXT', bbox: { x: -560, y: -560, width: 160, height: 20 }, characters: 'More options' } ] },
94
+ { id: 'A:dash', name: 'Dashboard', type: 'TEXT', bbox: { x: 16, y: 16, width: 120, height: 20 }, characters: 'Dashboard' },
95
+ ] },
96
+ ] },
97
+ { id: 'A:pag', name: 'pagination-wrap', type: 'INSTANCE', bbox: { x: 0, y: 860, width: 1440, height: 40 },
98
+ children: [
99
+ // hidden overflow row parked far to the right
100
+ { id: 'A:overflow', name: 'overflow-pages', type: 'FRAME', visible: false, layoutMode: 'HORIZONTAL', bbox: { x: 2200, y: 860, width: 300, height: 40 }, children: [] },
101
+ ] },
102
+ { id: 'A:content', name: 'content', type: 'FRAME', layoutMode: 'VERTICAL', bbox: { x: 240, y: 0, width: 1200, height: 900 },
103
+ children: [ { id: 'A:title', name: 'Model Management', type: 'TEXT', bbox: { x: 272, y: 24, width: 300, height: 28 }, characters: 'Model Management' } ] },
104
+ ],
105
+ };
106
+
107
+ const fixtureB = {
108
+ id: '0:0', name: 'B-screen', type: 'FRAME', layoutMode: 'VERTICAL', bbox: { x: 0, y: 0, width: 1000, height: 600 },
109
+ children: [
110
+ { id: 'B:panel', name: 'panel', type: 'FRAME', layoutMode: 'VERTICAL', bbox: { x: 0, y: 0, width: 1000, height: 300 },
111
+ children: [
112
+ // authored TEXT wider than its parent → real textClip (must be caught)
113
+ { id: 'B:title', name: 'clipped-title', type: 'TEXT', bbox: { x: 0, y: 0, width: 1100, height: 30 }, characters: 'a title that runs past the panel edge' },
114
+ ] },
115
+ { id: 'B:badge', name: 'status-badge', type: 'INSTANCE', bbox: { x: 0, y: 320, width: 80, height: 24 },
116
+ children: [
117
+ // VISIBLE TEXT clipped inside an instance → still caught (label-clipping intent preserved)
118
+ { id: 'B:label', name: 'OVERFLOWING-LABEL', type: 'TEXT', bbox: { x: 0, y: 320, width: 140, height: 24 }, characters: 'OVERFLOWING-LABEL' },
119
+ // VISIBLE non-text interior layer extending past its parent → IGNORED (DS internals = check1's job)
120
+ { id: 'B:deco', name: 'decoration', type: 'FRAME', bbox: { x: 10, y: 300, width: 40, height: 15 }, children: [] },
121
+ // hidden interior → skipped entirely
122
+ { id: 'B:tip', name: 'hidden-tooltip', type: 'FRAME', visible: false, layoutMode: 'VERTICAL', bbox: { x: 500, y: 320, width: 200, height: 100 }, children: [] },
123
+ ] },
124
+ ],
125
+ };
126
+
127
+ // ---- assertions ------------------------------------------------------------
128
+ let failed = 0;
129
+ function ok(cond, msg) { if (cond) { console.log(' PASS ' + msg); } else { console.log(' FAIL ' + msg); failed++; } }
130
+
131
+ (async () => {
132
+ // Fixture A — regression: hidden off-frame interiors must NOT produce hardFails.
133
+ const a = await runCheckLayout(buildFigma(fixtureA));
134
+ console.log('Fixture A (hidden off-frame DS interiors):', JSON.stringify(a.hardFails));
135
+ ok(a.hardFails.length === 0, 'A: hardFails == 0 (was ~70 outOfFrame pre-fix)');
136
+
137
+ // Fixture B — over-correction guard: real breakage caught, visible non-text interior ignored.
138
+ const b = await runCheckLayout(buildFigma(fixtureB));
139
+ console.log('Fixture B (real breakage + interior overflow):', JSON.stringify(b.hardFails));
140
+ const clips = b.hardFails.filter((f) => f.type === 'textClip').map((f) => f.node);
141
+ ok(clips.includes('clipped-title'), 'B: authored clipped TEXT caught (textClip)');
142
+ ok(clips.includes('OVERFLOWING-LABEL'), 'B: clipped VISIBLE label inside instance caught (textClip)');
143
+ ok(!b.hardFails.some((f) => f.node === 'decoration'), 'B: visible non-text interior overflow NOT flagged');
144
+ ok(!b.hardFails.some((f) => f.node === 'hidden-tooltip'), 'B: hidden interior NOT flagged');
145
+ ok(b.hardFails.length === 2, 'B: exactly 2 hardFails (no spurious overlap/junk)');
146
+
147
+ console.log('');
148
+ if (failed) { console.log('check-layout regression: ' + failed + ' assertion(s) FAILED'); process.exit(1); }
149
+ console.log('check-layout regression: all assertions passed');
150
+ })().catch((e) => { console.error(e); process.exit(1); });