From a9fb92734f5510c770ae7fb0aa6981a0b2d08927 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Sat, 21 Nov 2026 09:08:55 -0800 Subject: [PATCH 1/2] fix(schema): require project unless project-si-source is set A file without header.project-si-source now has to include project, and a child file that sets it has to include repository, which is what the field descriptions already say. The editor's CUE parser skips the conditional blocks so the fallback schema stays the same. Fixes #119 Signed-off-by: Srinivas Chippagiri --- docs/editor/js/cue-parser.js | 20 ++++++++++++++++++++ spec/schema.cue | 10 ++++++++++ tests/editor/parser-export.test.js | 13 +++++++++++++ tests/schema/required-fields.test.js | 27 +++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/docs/editor/js/cue-parser.js b/docs/editor/js/cue-parser.js index 49eb532..ffa9fd0 100644 --- a/docs/editor/js/cue-parser.js +++ b/docs/editor/js/cue-parser.js @@ -536,6 +536,14 @@ const CueParser = (function() { let fieldName; let fieldLine; + // Conditional fields (`if cond { ... }`) only tighten requirements + // that `cue vet` checks; the editor keeps the plain field definitions. + if (this.check(TokenType.IDENTIFIER) && this.peek().value === 'if' && + this.peek(1).type !== TokenType.COLON && this.peek(1).type !== TokenType.QUESTION) { + this.skipComprehension(); + continue; + } + if (this.check(TokenType.IDENTIFIER)) { const token = this.advance(); fieldName = token.value; @@ -580,6 +588,18 @@ const CueParser = (function() { }; } + skipComprehension() { + while (!this.check(TokenType.LBRACE) && !this.check(TokenType.EOF)) { + this.advance(); + } + let depth = 0; + do { + const token = this.advance(); + if (token.type === TokenType.LBRACE) depth++; + if (token.type === TokenType.RBRACE) depth--; + } while (depth > 0 && !this.check(TokenType.EOF)); + } + parseFieldType() { // Check for disjunction (enum) starting with string literal if (this.check(TokenType.STRING)) { diff --git a/spec/schema.cue b/spec/schema.cue index 0903403..f249393 100644 --- a/spec/schema.cue +++ b/spec/schema.cue @@ -113,6 +113,16 @@ import ( // repository describes repository-related configurations, including status, policies, team members, documentation, license, releases, and security posture. Required for single-repository files and for child files in a multi-repository project (i.e. files that set `header.project-si-source`). Optional in a parent file when project-level information is the only thing the parent contributes. repository?: #Repository + + // A file without `header.project-si-source` must carry its own project information. + if header["project-si-source"] == _|_ { + project!: #Project + } + + // A child file that inherits project information must describe its repository. + if header["project-si-source"] != _|_ { + repository!: #Repository + } } // The Header object captures high-level metadata about the schema. diff --git a/tests/editor/parser-export.test.js b/tests/editor/parser-export.test.js index a2f1e90..a5d7aeb 100644 --- a/tests/editor/parser-export.test.js +++ b/tests/editor/parser-export.test.js @@ -46,6 +46,19 @@ test('parser defaults to unknown version and accepts explicit metadata', () => { ); }); +test('parser keeps a field that is named if', () => { + const parsed = CueParser.parse([ + '#Thing: {', + ' if: string', + ' name?: string', + ' if cond {', + ' other!: string', + ' }', + '}' + ].join('\n')); + assert.deepEqual(Object.keys(parsed.getType('#Thing').fields), ['if', 'name']); +}); + test('fetchAndParse carries optional version metadata without a default', async () => { const originalFetch = global.fetch; global.fetch = async () => ({ diff --git a/tests/schema/required-fields.test.js b/tests/schema/required-fields.test.js index 67a1ab4..66da9f8 100644 --- a/tests/schema/required-fields.test.js +++ b/tests/schema/required-fields.test.js @@ -55,3 +55,30 @@ test('repository.security.tools[].results: an empty object is accepted', () => { const result = vet(withToolResults({})); assert.equal(result.status, 0, result.stderr); }); + +const childExample = yaml.load(fs.readFileSync( + path.join(root, 'examples', 'example-multi-repository-project-reuse.yml'), 'utf8')); + +test('project: omitting it without header.project-si-source is rejected', () => { + const document = structuredClone(example); + delete document.project; + const result = vet(document); + assert.notEqual(result.status, 0); + assert.match(result.stderr, /project: field is required but not present/); +}); + +test('project: a parent file with only header and project is accepted', () => { + const result = vet({ header: example.header, project: example.project }); + assert.equal(result.status, 0, result.stderr); +}); + +test('repository: omitting it with header.project-si-source is rejected', () => { + const result = vet({ header: childExample.header }); + assert.notEqual(result.status, 0); + assert.match(result.stderr, /repository: field is required but not present/); +}); + +test('project: a child file with header.project-si-source may omit it', () => { + const result = vet(childExample); + assert.equal(result.status, 0, result.stderr); +}); From c511cacffd64008c4d5a60c13902ad28493fdbf5 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Mon, 23 Nov 2026 19:08:39 -0800 Subject: [PATCH 2/2] docs(llm-prompt): repin the schema after the project rule Points SCHEMA_URL at the schema commit and updates SCHEMA_SHA256. Signed-off-by: Srinivas Chippagiri --- docs/LLM_PROMPT.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/LLM_PROMPT.md b/docs/LLM_PROMPT.md index 020747d..518becb 100644 --- a/docs/LLM_PROMPT.md +++ b/docs/LLM_PROMPT.md @@ -22,8 +22,8 @@ rather than invent required facts. ```text SPEC_VERSION: v2.2.0 -SCHEMA_URL: https://raw.githubusercontent.com/ossf/security-insights/65a6f2e0506eb902f8b2b82b7da468cea5438a3e/spec/schema.cue -SCHEMA_SHA256: 441600f66896a7c1e47e12afb44efa782b4225dae8e37e072a7e24db1b1f7b63 +SCHEMA_URL: https://raw.githubusercontent.com/ossf/security-insights/a9fb92734f5510c770ae7fb0aa6981a0b2d08927/spec/schema.cue +SCHEMA_SHA256: a8343235b3cd8730b355e6b9880ed09debce850ceaf963552ff87e9f45bf5a8d REPOSITORY: CANONICAL_FILE_URL: