@airalogy/aimd-recorder 1.22.0 → 1.24.0

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.
Files changed (95) hide show
  1. package/README.md +80 -0
  2. package/README.zh-CN.md +80 -0
  3. package/dist/{AimdCodeField-BN_0UQMx.js → AimdCodeField-CPjcXY4D.js} +1 -1
  4. package/dist/{AimdDnaSequenceField-Bhj28fP8.js → AimdDnaSequenceField-Dz-IONoA.js} +5 -4
  5. package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-D7c01UqN.js → AimdEditor.vue_vue_type_style_index_0_lang-JAD--qFs.js} +1999 -1900
  6. package/dist/AimdEntityRefField-BE0s2o5T.js +229 -0
  7. package/dist/{AimdMarkdownField-GS15pv4z.js → AimdMarkdownField-BeD2t9JY.js} +5 -5
  8. package/dist/{AimdMarkdownNoteField-H9WP8tR6.js → AimdMarkdownNoteField-DIgGEYpj.js} +16 -16
  9. package/dist/{_commonjsHelpers-B5RozER-.js → _commonjsHelpers-ByX85dGu.js} +12 -19
  10. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  11. package/dist/aimd-recorder.css +1 -1
  12. package/dist/{arc-B50G9-kH.js → arc-CLJJdrm0.js} +1 -1
  13. package/dist/{architectureDiagram-3BPJPVTR-D9mBEbpY.js → architectureDiagram-3BPJPVTR-BizrFPnS.js} +3 -3
  14. package/dist/{blockDiagram-GPEHLZMM-Cs4swgto.js → blockDiagram-GPEHLZMM-IHDih8JW.js} +4 -4
  15. package/dist/{c4Diagram-AAUBKEIU-C12HKS3r.js → c4Diagram-AAUBKEIU-BQtg8m_M.js} +2 -2
  16. package/dist/{channel-D69VnjVz.js → channel-D8q7AX1Z.js} +1 -1
  17. package/dist/{chunk-2J33WTMH-oc-89G5c.js → chunk-2J33WTMH-C24lbKon.js} +1 -1
  18. package/dist/{chunk-4BX2VUAB-BDJS9G3r.js → chunk-4BX2VUAB-1m_lB_xe.js} +1 -1
  19. package/dist/{chunk-55IACEB6-BPl3uHcA.js → chunk-55IACEB6-BE5Nj-sd.js} +1 -1
  20. package/dist/{chunk-727SXJPM-pWe-vDGf.js → chunk-727SXJPM-Cg-Xw_d_.js} +5 -5
  21. package/dist/{chunk-AQP2D5EJ-D-R5sIr1.js → chunk-AQP2D5EJ-BvRpPCiY.js} +3 -3
  22. package/dist/{chunk-FMBD7UC4-bo6Qyom1.js → chunk-FMBD7UC4-D_44MTsg.js} +1 -1
  23. package/dist/{chunk-ND2GUHAM-DQMvtYV7.js → chunk-ND2GUHAM-tVBIo4LA.js} +1 -1
  24. package/dist/{chunk-QZHKN3VN-DlCn3HON.js → chunk-QZHKN3VN-B91HYLks.js} +1 -1
  25. package/dist/{classDiagram-v2-Q7XG4LA2-DzUwWFwr.js → classDiagram-4FO5ZUOK-CkejvTAN.js} +2 -2
  26. package/dist/{classDiagram-4FO5ZUOK-DzUwWFwr.js → classDiagram-v2-Q7XG4LA2-CkejvTAN.js} +2 -2
  27. package/dist/components.js +3869 -3359
  28. package/dist/composables.js +98 -93
  29. package/dist/{cose-bilkent-S5V4N54A-BXLMzfpO.js → cose-bilkent-S5V4N54A-CNcuriOF.js} +2 -2
  30. package/dist/{dagre-BM42HDAG-DHnofIh9.js → dagre-BM42HDAG-DMqFGafq.js} +3 -3
  31. package/dist/{diagram-2AECGRRQ-BqTTVPsm.js → diagram-2AECGRRQ-Cksd3pP3.js} +2 -2
  32. package/dist/{diagram-5GNKFQAL-D5p1UVbw.js → diagram-5GNKFQAL-SVjLnDJG.js} +3 -3
  33. package/dist/{diagram-KO2AKTUF-Uuoz9cFn.js → diagram-KO2AKTUF-DfNIAG6w.js} +2 -2
  34. package/dist/{diagram-LMA3HP47-W001U31X.js → diagram-LMA3HP47-DPOyCMGB.js} +2 -2
  35. package/dist/{diagram-OG6HWLK6-DL516LDr.js → diagram-OG6HWLK6-BDURmT37.js} +3 -3
  36. package/dist/{erDiagram-TEJ5UH35-CCxgMb67.js → erDiagram-TEJ5UH35-N991qII9.js} +4 -4
  37. package/dist/{flowDiagram-I6XJVG4X-nXGdmC0O.js → flowDiagram-I6XJVG4X-BABRFuk-.js} +6 -6
  38. package/dist/{ganttDiagram-6RSMTGT7-Bi9Ro7_Z.js → ganttDiagram-6RSMTGT7-BMDnK96S.js} +3 -3
  39. package/dist/{gitGraphDiagram-PVQCEYII-w1kNAy4E.js → gitGraphDiagram-PVQCEYII-cEvL7Dss.js} +3 -3
  40. package/dist/{graph-CpOkL_eZ.js → graph-BA09aCvZ.js} +1 -1
  41. package/dist/index.js +125 -113
  42. package/dist/{infoDiagram-5YYISTIA-Bde_w9T1.js → infoDiagram-5YYISTIA-DpC1Zthd.js} +1 -1
  43. package/dist/{ishikawaDiagram-YF4QCWOH-x5M1KR0l.js → ishikawaDiagram-YF4QCWOH-CMEt_f-x.js} +1 -1
  44. package/dist/{journeyDiagram-JHISSGLW-CIDQP8Zm.js → journeyDiagram-JHISSGLW-C0Qw169C.js} +4 -4
  45. package/dist/{kanban-definition-UN3LZRKU-CKgO7sG8.js → kanban-definition-UN3LZRKU-caROmSUy.js} +2 -2
  46. package/dist/{layout-BZYprqYR.js → layout-CH65__O4.js} +2 -2
  47. package/dist/{linear-ClSH2F_v.js → linear-B1VXpcsy.js} +1 -1
  48. package/dist/{mermaid.core-CcRV6K2R.js → mermaid.core-Cbmwvfvk.js} +35 -35
  49. package/dist/{mindmap-definition-RKZ34NQL-s3h6uszV.js → mindmap-definition-RKZ34NQL-DpTR5ilS.js} +3 -3
  50. package/dist/{pieDiagram-4H26LBE5-CgiazyWv.js → pieDiagram-4H26LBE5-Cb_KrmWC.js} +3 -3
  51. package/dist/{quadrantDiagram-W4KKPZXB-DCPVgHoW.js → quadrantDiagram-W4KKPZXB-B5_NswmK.js} +2 -2
  52. package/dist/record.js +77 -72
  53. package/dist/{requirementDiagram-4Y6WPE33-DE6F9oSB.js → requirementDiagram-4Y6WPE33-OFwfat5D.js} +3 -3
  54. package/dist/{sankeyDiagram-5OEKKPKP-DZZoFFr-.js → sankeyDiagram-5OEKKPKP-BaawdZEE.js} +1 -1
  55. package/dist/{sequenceDiagram-3UESZ5HK-DaYEOl60.js → sequenceDiagram-3UESZ5HK-DLv8X8ef.js} +3 -3
  56. package/dist/{stateDiagram-AJRCARHV-BmgpHJlH.js → stateDiagram-AJRCARHV-B6F3wrsd.js} +4 -4
  57. package/dist/{stateDiagram-v2-BHNVJYJU-D49CHQD6.js → stateDiagram-v2-BHNVJYJU-BcNEoshv.js} +2 -2
  58. package/dist/{timeline-definition-PNZ67QCA-DdVLoCkC.js → timeline-definition-PNZ67QCA-CvdHJ4eQ.js} +2 -2
  59. package/dist/useCodeBlockRendering-D2viVPtA.js +3158 -0
  60. package/dist/useFieldRendering-Co4DOOvL.js +1120 -0
  61. package/dist/useVarHelpers-Du2obGza.js +3474 -0
  62. package/dist/validation-oyqyD7Jp.js +5601 -0
  63. package/dist/{vennDiagram-CIIHVFJN-CCcMKcd7.js → vennDiagram-CIIHVFJN-U0GlQDjX.js} +1 -1
  64. package/dist/{wardleyDiagram-YWT4CUSO-R4UGgGWY.js → wardleyDiagram-YWT4CUSO-CzF_KMcn.js} +2 -2
  65. package/dist/{xychartDiagram-2RQKCTM6-DyFhCubk.js → xychartDiagram-2RQKCTM6-Cljki2Vk.js} +2 -2
  66. package/package.json +6 -4
  67. package/src/__tests__/collector-field.test.ts +269 -0
  68. package/src/__tests__/record-search-render.test.ts +1 -0
  69. package/src/__tests__/record-validation.test.ts +378 -0
  70. package/src/__tests__/recorder-wysiwyg-field-host.test.ts +26 -0
  71. package/src/__tests__/var-field-render.test.ts +64 -2
  72. package/src/components/AimdCollectorField.vue +233 -0
  73. package/src/components/AimdEntityRefField.vue +314 -0
  74. package/src/components/AimdRecorder.vue +285 -7
  75. package/src/components/AimdRecorderEditor.vue +51 -1
  76. package/src/components/AimdRecorderWysiwygFieldHost.vue +10 -0
  77. package/src/components/AimdRecorderWysiwygSurface.vue +166 -4
  78. package/src/components/AimdVarField.vue +39 -2
  79. package/src/components/AimdVarTableField.vue +38 -21
  80. package/src/components/index.ts +4 -0
  81. package/src/components/recorderMilkdownPlugin.ts +16 -0
  82. package/src/composables/__tests__/useVarHelpers.test.ts +32 -0
  83. package/src/composables/index.ts +12 -0
  84. package/src/composables/useCollectors.ts +399 -0
  85. package/src/composables/useVarHelpers.ts +130 -2
  86. package/src/index.ts +32 -2
  87. package/src/locales.ts +140 -2
  88. package/src/record/index.ts +14 -0
  89. package/src/record/validation.ts +772 -0
  90. package/src/styles/collector-field.css +281 -0
  91. package/src/styles/recorder-surface.css +163 -0
  92. package/src/styles/recorder.css +33 -0
  93. package/src/types.ts +168 -1
  94. package/dist/index-Dkrf2LJl.js +0 -1308
  95. package/dist/useCodeBlockRendering-CCuoP52e.js +0 -6103
@@ -0,0 +1,378 @@
1
+ import type { ExtractedAimdFields } from "@airalogy/aimd-core/types"
2
+ import { flushPromises, mount } from "@vue/test-utils"
3
+ import { describe, expect, it, vi } from "vitest"
4
+ import AimdRecorder from "../components/AimdRecorder.vue"
5
+ import { createAimdRecorderMessages } from "../locales"
6
+ import { validateAimdField, validateAimdRecord } from "../record/validation"
7
+ import { createEmptyProtocolRecordData } from "../types"
8
+
9
+ const EMPTY_FIELDS: ExtractedAimdFields = {
10
+ var: [],
11
+ var_definitions: [],
12
+ var_table: [],
13
+ client_assigner: [],
14
+ quiz: [],
15
+ step: [],
16
+ check: [],
17
+ ref_step: [],
18
+ ref_var: [],
19
+ }
20
+
21
+ const messages = createAimdRecorderMessages("en-US").validation
22
+
23
+ describe("AimdRecorder validation", () => {
24
+ it("validates inferred required, pattern, numeric, and every table cell constraint", () => {
25
+ const record = createEmptyProtocolRecordData()
26
+ record.var.code = "bad"
27
+ record.var.temperature = 12
28
+ record.var.samples = [{ concentration: "", sample_id: "" }]
29
+
30
+ const result = validateAimdRecord({
31
+ ...EMPTY_FIELDS,
32
+ var: ["name", "code", "temperature"],
33
+ var_definitions: [
34
+ { id: "name", title: "Name" },
35
+ { id: "code", title: "Code", kwargs: { pattern: "^[A-Z]+$" } },
36
+ { id: "temperature", title: "Temperature", type: "float", kwargs: { lt: 10 } },
37
+ ],
38
+ var_table: [{
39
+ id: "samples",
40
+ scope: "var_table",
41
+ subvars: [
42
+ { id: "concentration", title: "Concentration" },
43
+ { id: "sample_id", title: "Sample ID" },
44
+ ],
45
+ }],
46
+ }, record, {
47
+ fieldMeta: {
48
+ "var_table:samples:concentration": { required: true },
49
+ "var_table:samples:sample_id": { required: true },
50
+ },
51
+ messages,
52
+ })
53
+
54
+ expect(result.valid).toBe(false)
55
+ expect(result.issues.map(issue => [issue.fieldKey, issue.code])).toEqual([
56
+ ["var:name", "required"],
57
+ ["var:code", "pattern"],
58
+ ["var:temperature", "numeric"],
59
+ ["var_table:samples:0:concentration", "required"],
60
+ ["var_table:samples:0:sample_id", "required"],
61
+ ])
62
+ expect(result.fieldState["var_table:samples:0:concentration"]?.validationError).toContain("Row 1")
63
+ })
64
+
65
+ it("consumes Pydantic JSON Schema as the authoritative validation contract", () => {
66
+ const record = createEmptyProtocolRecordData()
67
+ record.var.name = ""
68
+ record.var.age = "17"
69
+ record.var.started_at = "not-a-date"
70
+ record.var.status = "unknown"
71
+ record.var.samples = [{ concentration: "bad", code: "" }]
72
+
73
+ const fields: ExtractedAimdFields = {
74
+ ...EMPTY_FIELDS,
75
+ var: ["name", "age", "started_at", "status"],
76
+ var_definitions: [
77
+ { id: "name", title: "Name", type: "str" },
78
+ { id: "age", title: "Age", type: "int" },
79
+ { id: "started_at", title: "Started at", type: "datetime" },
80
+ { id: "status", title: "Status", type: "str" },
81
+ ],
82
+ var_table: [{
83
+ id: "samples",
84
+ scope: "var_table",
85
+ subvars: [
86
+ { id: "concentration", title: "Concentration", type: "float" },
87
+ { id: "code", title: "Code", type: "str" },
88
+ ],
89
+ }],
90
+ }
91
+
92
+ const result = validateAimdRecord(fields, record, {
93
+ schema: {
94
+ vars: {
95
+ type: "object",
96
+ required: ["name", "age", "started_at", "status", "samples"],
97
+ properties: {
98
+ name: { type: "string", minLength: 1 },
99
+ age: { type: "integer", minimum: 18 },
100
+ started_at: { type: "string", format: "date-time" },
101
+ status: { enum: ["draft", "complete"] },
102
+ samples: {
103
+ type: "array",
104
+ items: {
105
+ type: "object",
106
+ required: ["concentration", "code"],
107
+ properties: {
108
+ concentration: { type: "number", exclusiveMinimum: 0 },
109
+ code: { type: "string", pattern: "^[A-Z]+$" },
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ messages,
117
+ })
118
+
119
+ expect(result.valid).toBe(false)
120
+ expect(result.issues).toEqual(expect.arrayContaining([
121
+ expect.objectContaining({ fieldKey: "var:name", code: "required" }),
122
+ expect.objectContaining({ fieldKey: "var:age", code: "numeric" }),
123
+ expect.objectContaining({ fieldKey: "var:started_at", code: "format" }),
124
+ expect.objectContaining({ fieldKey: "var:status", code: "enum" }),
125
+ expect.objectContaining({ fieldKey: "var_table:samples:0:concentration", code: "type" }),
126
+ expect.objectContaining({ fieldKey: "var_table:samples:0:code", code: "required" }),
127
+ ]))
128
+ })
129
+
130
+ it("resolves required table columns through Pydantic local references", () => {
131
+ const record = createEmptyProtocolRecordData()
132
+ record.var.samples = [{ code: "" }]
133
+ const fields: ExtractedAimdFields = {
134
+ ...EMPTY_FIELDS,
135
+ var_table: [{
136
+ id: "samples",
137
+ scope: "var_table",
138
+ subvars: [{ id: "code", type: "str" }],
139
+ }],
140
+ }
141
+
142
+ const result = validateAimdRecord(fields, record, {
143
+ schema: {
144
+ vars: {
145
+ type: "object",
146
+ required: ["samples"],
147
+ properties: {
148
+ samples: { type: "array", items: { $ref: "#/$defs/Sample" } },
149
+ },
150
+ $defs: {
151
+ Sample: {
152
+ type: "object",
153
+ required: ["code"],
154
+ properties: { code: { type: "string" } },
155
+ },
156
+ },
157
+ },
158
+ },
159
+ messages,
160
+ })
161
+
162
+ expect(result.issues).toEqual([
163
+ expect.objectContaining({
164
+ fieldKey: "var_table:samples:0:code",
165
+ code: "required",
166
+ }),
167
+ ])
168
+ })
169
+
170
+ it("reports an empty schema-required numeric input as required instead of a type error", () => {
171
+ const record = createEmptyProtocolRecordData()
172
+ record.var.count = ""
173
+
174
+ const result = validateAimdRecord({
175
+ ...EMPTY_FIELDS,
176
+ var: ["count"],
177
+ var_definitions: [{ id: "count", type: "int" }],
178
+ }, record, {
179
+ schema: {
180
+ vars: {
181
+ type: "object",
182
+ required: ["count"],
183
+ properties: { count: { type: "integer" } },
184
+ },
185
+ },
186
+ messages,
187
+ })
188
+
189
+ expect(result.issues).toEqual([
190
+ expect.objectContaining({ fieldKey: "var:count", code: "required" }),
191
+ ])
192
+ })
193
+
194
+ it("lets a supplied schema override an AIMD annotation without duplicating Python rules", () => {
195
+ const record = createEmptyProtocolRecordData()
196
+ record.var.age = "custom-model-string"
197
+
198
+ const result = validateAimdRecord({
199
+ ...EMPTY_FIELDS,
200
+ var: ["age"],
201
+ var_definitions: [{ id: "age", type: "int", kwargs: { ge: 18 } }],
202
+ }, record, {
203
+ schema: {
204
+ research_variable: {
205
+ type: "object",
206
+ required: ["age"],
207
+ properties: { age: { type: "string" } },
208
+ },
209
+ },
210
+ messages,
211
+ })
212
+
213
+ expect(result).toEqual({ valid: true, issues: [], fieldState: {} })
214
+ })
215
+
216
+ it("normalizes file wrappers and validates ordinary array and object values with the schema", () => {
217
+ const record = createEmptyProtocolRecordData()
218
+ record.var.attachment = { airalogy_file_id: "airalogy.id.file.report.pdf" }
219
+ record.var.tags = ["alpha", "beta"]
220
+ record.var.settings = { enabled: true }
221
+
222
+ const result = validateAimdRecord({
223
+ ...EMPTY_FIELDS,
224
+ var: ["attachment", "tags", "settings"],
225
+ var_definitions: [
226
+ { id: "attachment", type: "FileIdPDF" },
227
+ { id: "tags", type: "list[str]" },
228
+ { id: "settings", type: "dict" },
229
+ ],
230
+ }, record, {
231
+ schema: {
232
+ vars: {
233
+ type: "object",
234
+ required: ["attachment", "tags", "settings"],
235
+ properties: {
236
+ attachment: { type: "string", pattern: "^airalogy\\.id\\.file\\." },
237
+ tags: { type: "array", minItems: 2, items: { type: "string" } },
238
+ settings: {
239
+ type: "object",
240
+ required: ["enabled"],
241
+ properties: { enabled: { type: "boolean" } },
242
+ },
243
+ },
244
+ },
245
+ },
246
+ messages,
247
+ })
248
+
249
+ expect(result.valid).toBe(true)
250
+ })
251
+
252
+ it("can validate and clear one exact table cell without collapsing to the table key", () => {
253
+ const record = createEmptyProtocolRecordData()
254
+ record.var.samples = [{ concentration: "", sample_id: "" }]
255
+ const fields: ExtractedAimdFields = {
256
+ ...EMPTY_FIELDS,
257
+ var_table: [{
258
+ id: "samples",
259
+ scope: "var_table",
260
+ subvars: [{ id: "concentration" }, { id: "sample_id" }],
261
+ }],
262
+ }
263
+
264
+ const result = validateAimdField(fields, record, "var_table:samples:0:sample_id", {
265
+ fieldMeta: {
266
+ "var_table:samples:concentration": { required: true },
267
+ "var_table:samples:sample_id": { required: true },
268
+ },
269
+ messages,
270
+ })
271
+
272
+ expect(result.issues).toHaveLength(1)
273
+ expect(result.issues[0]).toMatchObject({
274
+ fieldKey: "var_table:samples:0:sample_id",
275
+ rowIndex: 0,
276
+ column: "sample_id",
277
+ })
278
+ expect(result.validatedFieldKeys).toEqual(["var_table:samples:0:sample_id"])
279
+ })
280
+
281
+ it("validates on change and preserves errors belonging to other fields", async () => {
282
+ const wrapper = mount(AimdRecorder, {
283
+ attachTo: document.body,
284
+ props: {
285
+ content: "First: {{var|first: str}}\n\nSecond: {{var|second: str}}",
286
+ validationSchema: {
287
+ vars: {
288
+ type: "object",
289
+ required: ["first", "second"],
290
+ properties: {
291
+ first: { type: "string" },
292
+ second: { type: "string" },
293
+ },
294
+ },
295
+ },
296
+ showSearch: false,
297
+ },
298
+ })
299
+ await flushPromises()
300
+
301
+ const recorder = wrapper.vm as unknown as {
302
+ validate: (options?: { focus?: boolean }) => Promise<{ valid: boolean }>
303
+ }
304
+ expect((await recorder.validate({ focus: false })).valid).toBe(false)
305
+ await flushPromises()
306
+ expect(wrapper.findAll(".aimd-rec-validation-message")).toHaveLength(2)
307
+
308
+ await wrapper.get('textarea[data-rec-focus-key="var:first"]').setValue("Alice")
309
+ await flushPromises()
310
+
311
+ const errors = wrapper.findAll(".aimd-rec-validation-message")
312
+ expect(errors).toHaveLength(1)
313
+ expect(errors[0].text()).toContain("second is required")
314
+ wrapper.unmount()
315
+ })
316
+
317
+ it("supports blur-only and submit-only immediate validation policies", async () => {
318
+ const wrapper = mount(AimdRecorder, {
319
+ props: {
320
+ content: "{{var|name: str}}",
321
+ validationTriggers: ["blur"],
322
+ showSearch: false,
323
+ },
324
+ })
325
+ await flushPromises()
326
+
327
+ const input = wrapper.get('textarea[data-rec-focus-key="var:name"]')
328
+ await input.setValue("Alice")
329
+ await input.setValue("")
330
+ await flushPromises()
331
+ expect(wrapper.find(".aimd-rec-validation-message").exists()).toBe(false)
332
+
333
+ await input.trigger("blur")
334
+ await flushPromises()
335
+ expect(wrapper.find(".aimd-rec-validation-message").exists()).toBe(true)
336
+
337
+ await wrapper.setProps({ validationTriggers: ["submit"] })
338
+ const recorder = wrapper.vm as unknown as {
339
+ clearValidation: () => void
340
+ validate: (options?: { focus?: boolean }) => Promise<{ valid: boolean }>
341
+ }
342
+ recorder.clearValidation()
343
+ await flushPromises()
344
+ await input.setValue("Bob")
345
+ await input.setValue("")
346
+ await input.trigger("blur")
347
+ await flushPromises()
348
+ expect(wrapper.find(".aimd-rec-validation-message").exists()).toBe(false)
349
+ expect((await recorder.validate({ focus: false })).valid).toBe(false)
350
+ wrapper.unmount()
351
+ })
352
+
353
+ it("renders and focuses the exact invalid table cell", async () => {
354
+ HTMLElement.prototype.scrollIntoView = vi.fn()
355
+ const wrapper = mount(AimdRecorder, {
356
+ attachTo: document.body,
357
+ props: {
358
+ content: "{{var_table|samples, subvars=[concentration: float, sample_id: str]}}",
359
+ fieldMeta: {
360
+ "var_table:samples:concentration": { required: true },
361
+ "var_table:samples:sample_id": { required: true },
362
+ },
363
+ showSearch: false,
364
+ },
365
+ })
366
+ await flushPromises()
367
+
368
+ const recorder = wrapper.vm as unknown as {
369
+ validate: (options?: { focus?: boolean }) => Promise<{ valid: boolean }>
370
+ }
371
+ expect((await recorder.validate()).valid).toBe(false)
372
+ await flushPromises()
373
+
374
+ expect(wrapper.find('[data-aimd-validation-field="var_table:samples:0:concentration"] .aimd-rec-validation-message').exists()).toBe(true)
375
+ expect(document.activeElement?.getAttribute("data-rec-focus-key")).toBe("var_table:samples:0:concentration")
376
+ wrapper.unmount()
377
+ })
378
+ })
@@ -12,6 +12,8 @@ function createSurfaceState(): RecorderMilkdownSurfaceState {
12
12
  choiceOptionExplanationMode: 'hidden',
13
13
  scaleGradeDisplayMode: 'hidden',
14
14
  stepDetailDisplay: 'auto',
15
+ validationTriggers: ['change', 'blur'],
16
+ validationEpoch: 0,
15
17
  onUpdateRecord: () => {},
16
18
  }
17
19
  }
@@ -33,4 +35,28 @@ describe('AimdRecorderWysiwygFieldHost', () => {
33
35
  expect(wrapper.html()).toContain('data-rec-focus-key="var:sample_name"')
34
36
  expect(wrapper.html()).not.toContain('aimd-field-chip')
35
37
  })
38
+
39
+ it('forwards the shared validation contract into embedded recorders', () => {
40
+ const schema = {
41
+ vars: {
42
+ type: 'object',
43
+ required: ['sample_name'],
44
+ properties: { sample_name: { type: 'string', minLength: 1 } },
45
+ },
46
+ }
47
+ const surfaceState = createSurfaceState()
48
+ surfaceState.validationSchema = schema
49
+ surfaceState.validationTriggers = ['blur']
50
+
51
+ const wrapper = mount(AimdRecorderWysiwygFieldHost, {
52
+ props: {
53
+ surfaceState,
54
+ rawContent: '{{var|sample_name: str}}',
55
+ displayMode: 'inline',
56
+ },
57
+ })
58
+ const recorder = wrapper.getComponent({ name: 'AimdRecorder' })
59
+ expect(recorder.props('validationSchema')).toEqual(schema)
60
+ expect(recorder.props('validationTriggers')).toEqual(['blur'])
61
+ })
36
62
  })
@@ -291,9 +291,9 @@ describe('AimdVarField render behavior', () => {
291
291
  })
292
292
 
293
293
  it('places code assigner actions in the field header instead of a side prefix', () => {
294
- expect(source).toContain('["file", "code", "scalar-list"].includes(inputKind)')
294
+ expect(source).toContain('["file", "code", "scalar-list", "entity-ref"].includes(inputKind)')
295
295
  expect(source).toMatch(/if \(inputKind === "code"\) \{[\s\S]*?"aimd-rec-inline--var-stacked--code",[\s\S]*?\{ controlRow: false \}/)
296
- expect(recorderSource).toContain('["number", "date", "datetime", "time", "text", "textarea", "scalar-list", "checkbox", "boolean-select", "file", "code"].includes(inputKind)')
296
+ expect(recorderSource).toContain('["number", "date", "datetime", "time", "text", "textarea", "scalar-list", "entity-ref", "checkbox", "boolean-select", "file", "code"].includes(inputKind)')
297
297
  })
298
298
 
299
299
  it('renders nullable boolean vars as tri-state select fields', async () => {
@@ -1041,6 +1041,68 @@ describe('AimdVarField render behavior', () => {
1041
1041
  expect(latest?.var?.blood_type).toBeNull()
1042
1042
  })
1043
1043
 
1044
+ it('renders EntityRef vars with resolver-backed entity options', async () => {
1045
+ const search = vi.fn(async (query: string) => (
1046
+ query === 'pu'
1047
+ ? [{
1048
+ entity: 'plasmid',
1049
+ source: 'lab_plasmid_registry',
1050
+ id: 'pUC19',
1051
+ label: 'pUC19 cloning vector',
1052
+ description: 'Ampicillin resistance',
1053
+ }]
1054
+ : []
1055
+ ))
1056
+ const wrapper = mount(AimdRecorder, {
1057
+ props: {
1058
+ content: 'Parent: {{var|parent_plasmid: EntityRef | None, entity = "plasmid", source = "lab_plasmid_registry"}}',
1059
+ locale: 'en-US',
1060
+ modelValue: { var: {}, step: {}, check: {}, quiz: {} },
1061
+ entityResolvers: {
1062
+ lab_plasmid_registry: { search },
1063
+ },
1064
+ },
1065
+ })
1066
+
1067
+ await flushPromises()
1068
+ await wrapper.vm.$nextTick()
1069
+ await vi.dynamicImportSettled()
1070
+ await wrapper.vm.$nextTick()
1071
+
1072
+ const input = wrapper.find<HTMLInputElement>('input[data-rec-focus-key="var:parent_plasmid"]')
1073
+ expect(input.exists()).toBe(true)
1074
+ expect(input.attributes('placeholder')).toBe('Search plasmid')
1075
+
1076
+ await input.setValue('pu')
1077
+ await flushPromises()
1078
+ await vi.dynamicImportSettled()
1079
+ await wrapper.vm.$nextTick()
1080
+
1081
+ expect(search).toHaveBeenCalledWith('pu', expect.objectContaining({
1082
+ entity: 'plasmid',
1083
+ source: 'lab_plasmid_registry',
1084
+ fieldKey: 'var:parent_plasmid',
1085
+ multiple: false,
1086
+ }))
1087
+
1088
+ const option = wrapper.find('.aimd-rec-entity-ref__option')
1089
+ expect(option.exists()).toBe(true)
1090
+ expect(option.text()).toContain('pUC19 cloning vector')
1091
+
1092
+ await option.trigger('click')
1093
+ await flushPromises()
1094
+
1095
+ const updates = wrapper.emitted('update:modelValue') ?? []
1096
+ const latest = updates[updates.length - 1]?.[0] as { var?: Record<string, unknown> } | undefined
1097
+ expect(latest?.var?.parent_plasmid).toEqual({
1098
+ entity: 'plasmid',
1099
+ source: 'lab_plasmid_registry',
1100
+ id: 'pUC19',
1101
+ label: 'pUC19 cloning vector',
1102
+ description: 'Ampicillin resistance',
1103
+ })
1104
+ })
1105
+
1044
1106
  it('renders scalar list vars as repeatable inputs in AimdRecorder', async () => {
1045
1107
  const wrapper = mount(AimdRecorder, {
1046
1108
  props: {