filegrc 0.3.3 → 0.4.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.
package/src/workspace.js CHANGED
@@ -36,17 +36,25 @@ export async function loadWorkspace(input = process.cwd()) {
36
36
  });
37
37
  }
38
38
 
39
- let model;
40
- try {
41
- model = loadModel(String(workspaceEntry?.record?.dataModelVersion ?? "1"));
42
- } catch (error) {
39
+ let model = loadModel();
40
+ if (workspaceEntry && !Object.hasOwn(workspaceEntry.record, "dataModelVersion")) {
43
41
  diagnostics.push({
44
42
  severity: "error",
45
- code: "unsupported-model",
43
+ code: "missing-model-version",
46
44
  path: "data/workspace.json",
47
- message: error.message
45
+ message: "The Workspace record must declare dataModelVersion."
48
46
  });
49
- model = loadModel("1");
47
+ } else if (workspaceEntry) {
48
+ try {
49
+ model = loadModel(String(workspaceEntry.record.dataModelVersion));
50
+ } catch (error) {
51
+ diagnostics.push({
52
+ severity: "error",
53
+ code: "unsupported-model",
54
+ path: "data/workspace.json",
55
+ message: error.message
56
+ });
57
+ }
50
58
  }
51
59
 
52
60
  return {
@@ -1,69 +0,0 @@
1
- import { createResources } from "./files.js";
2
- import { createResourceId } from "./id.js";
3
- import { selectedControlFamilies } from "./program-readiness.js";
4
- import { loadWorkspace } from "./workspace.js";
5
-
6
- const TEST_EVIDENCE_KINDS = new Set(["test-export", "test-capture"]);
7
-
8
- export function planEvidenceTestDrafts(loaded) {
9
- const workspace = loaded.workspace;
10
- const selectedIds = new Set(workspace.controlIds || []);
11
- const controls = loaded.resources.filter((record) => (
12
- record.type === "control"
13
- && (!selectedIds.size || selectedIds.has(record.id))
14
- && !["not-applicable", "retired"].includes(record.status)
15
- ));
16
- const families = selectedControlFamilies(controls, loaded.model)
17
- .filter((family) => family.collectionTestRequired !== false);
18
- const evidence = loaded.resources.filter((record) => (
19
- record.type === "evidence" && TEST_EVIDENCE_KINDS.has(record.evidenceKind)
20
- ));
21
- return families.map((family) => {
22
- const familyControlIds = new Set(family.controls.map((control) => control.id));
23
- const existing = evidence.find((record) => record.collectionTestFamilyId === family.id)
24
- || evidence.find((record) => (
25
- (record.controlIds || []).some((id) => familyControlIds.has(id))
26
- ));
27
- return {
28
- familyId: family.id,
29
- title: family.title,
30
- testEvidenceKind: family.testEvidenceKind,
31
- testPrompt: family.testPrompt,
32
- controlIds: [...familyControlIds],
33
- existing
34
- };
35
- });
36
- }
37
-
38
- export async function ensureEvidenceTestDrafts(input = process.cwd()) {
39
- const loaded = await loadWorkspace(input);
40
- const plan = planEvidenceTestDrafts(loaded);
41
- const created = [];
42
- const usedIds = loaded.resources.map((record) => record.id);
43
- for (const item of plan.filter(({ existing }) => !existing)) {
44
- const id = createResourceId(
45
- "evidence",
46
- `${item.title} Collection Test`,
47
- usedIds
48
- );
49
- usedIds.push(id);
50
- const record = {
51
- schemaVersion: 1,
52
- id,
53
- type: "evidence",
54
- title: `${item.title} Evidence Collection Test`,
55
- status: "draft",
56
- evidenceKind: item.testEvidenceKind,
57
- collectionTestFamilyId: item.familyId,
58
- collectionTestPrompt: item.testPrompt,
59
- controlIds: item.controlIds
60
- };
61
- created.push(record);
62
- }
63
- if (created.length) await createResources(loaded.root, created);
64
- return {
65
- created,
66
- existing: plan.filter(({ existing }) => existing).map(({ existing }) => existing),
67
- total: plan.length
68
- };
69
- }