Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/LLM_PROMPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <GitHub repository URL or local repository path>
CANONICAL_FILE_URL: <intended raw URL of the published Insights file, or unknown>
Expand Down
20 changes: 20 additions & 0 deletions docs/editor/js/cue-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
10 changes: 10 additions & 0 deletions spec/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == _|_ {
Comment thread
jmeridth marked this conversation as resolved.
Resolved
project!: #Project

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 (medium) Heads-up: cue exp gengotypes reads this conditional project! as always required, so the generated Go field loses omitempty. ossf/si-tooling generates its types that way, so a regenerate there would start writing a project key into child files. As far as I can tell the @go optional attributes don't fix it, and splitting the rules into a separate definition does but needs parser changes. Is that worth handling here, or better as a follow-up with si-tooling?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the heads-up, I haven't run gengotypes against this. I'd rather leave the Go types to a follow-up with si-tooling than add parser changes here, unless you want it in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 A follow-up works for me. Could you open an issue on ossf/si-tooling describing the omitempty change, so it's tracked before the next type regeneration there?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened ossf/si-tooling#80 for it. thx

}

// 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.
Expand Down
13 changes: 13 additions & 0 deletions tests/editor/parser-export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => ({
Expand Down
27 changes: 27 additions & 0 deletions tests/schema/required-fields.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});