Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.10.0 (Preview) 2025-12-12

- Update to Cedar SDK 4.8.2

## v0.10.0 (Preview) 2025-11-12

- Update to Cedar SDK 4.7.0
Expand Down
408 changes: 201 additions & 207 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/cedar-policy/vscode-cedar/issues"
},
"qna": "https://github.com/cedar-policy/vscode-cedar/issues",
"version": "0.10.0",
"version": "0.10.1",
"preview": true,
"icon": "icons/cedar-policy.png",
"engines": {
Expand Down Expand Up @@ -303,13 +303,13 @@
"@types/mocha": "^10.0.10",
"@types/node": "=18.15.0",
"@types/vscode": "=1.83.0",
"@typescript-eslint/eslint-plugin": "^8.46.4",
"@typescript-eslint/parser": "^8.46.4",
"@typescript-eslint/eslint-plugin": "^8.49.0",
"@typescript-eslint/parser": "^8.49.0",
"@vscode/test-cli": "^0.0.12",
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "^3.7.0",
"@vscode/vsce": "^3.7.1",
"eslint": "^9.39.1",
"js-yaml": "^4.1.0",
"js-yaml": "^4.1.1",
"mocha": "^11.7.5",
"typescript": "^5.9.3"
}
Expand Down
17 changes: 10 additions & 7 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const addDiagnosticsError = (
diagnostics.push(diagnostic);
};

const determineRangeFromPolicyError = (
const determineRangeFromPolicyMessage = (
vpm: cedar.ValidateMessage,
policy: string,
defaultErrorRange: vscode.Range,
Expand Down Expand Up @@ -509,18 +509,19 @@ export const addValidationDiagnosticWarning = (
diagnostics.push(diagnostic);
};

export const addPolicyResultErrors = (
export const addPolicyResultMessages = (
diagnostics: vscode.Diagnostic[],
errors: cedar.ValidateMessage[],
messages: cedar.ValidateMessage[],
policy: string,
effectRange: vscode.Range,
startLine: number
startLine: number,
areWarnings: boolean
) => {
// create an error for each of the errors
errors.forEach((vpm) => {
messages.forEach((vpm) => {
let e = vpm.message;
let diagnosticCode = undefined;
let range = determineRangeFromPolicyError(
let range = determineRangeFromPolicyMessage(
vpm,
policy,
effectRange,
Expand Down Expand Up @@ -564,7 +565,9 @@ export const addPolicyResultErrors = (
const diagnostic = new vscode.Diagnostic(
range,
e,
vscode.DiagnosticSeverity.Error
areWarnings
? vscode.DiagnosticSeverity.Warning
: vscode.DiagnosticSeverity.Error
);
diagnostic.source = SOURCE_CEDAR;
if (diagnosticCode) {
Expand Down
61 changes: 46 additions & 15 deletions src/test/suite/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
MISMATCH_ATTR_REGEX,
NOTALLOWED_PARENT_REGEX,
NOTDECLARED_TYPE_REGEX,
OFFSET_POLICY_REGEX,
UNDECLARED_REGEX,
UNDECLARED_ACTION_REGEX,
UNRECOGNIZED_REGEX,
Expand All @@ -36,6 +35,43 @@ suite('Validation Schema Cedar Test Suite', () => {
// The name `ipaddr` shadows a builtin Cedar name. You'll have to refer to the builtin as `__cedar::ipaddr`.
// The name `String` shadows a builtin Cedar name. You'll have to refer to the builtin as `__cedar::String`.
assert.equal(result.warnings?.length, 2);
result.free();
});

test('validate __cedar reserved', async () => {
const schema = readTestDataFile('reserved', '__cedar.cedarschema');
const result: cedar.ValidateSchemaResult =
cedar.validateSchemaCedar(schema);
assert.equal(result.success, false);
// error parsing schema: use of the reserved `__cedar` namespace
assert.equal(result.errors?.length, 1);
if (result.errors) {
let e = result.errors[0];
assert.ok(e.message.includes('use of the reserved `__cedar` namespace'));
assert.equal(e.offset, 180);
assert.equal(e.length, 7);
}

result.free();
});

test('validate Set reserved', async () => {
const schema = readTestDataFile('reserved', 'set.cedarschema');
const result: cedar.ValidateSchemaResult =
cedar.validateSchemaCedar(schema);
assert.equal(result.success, false);
// error parsing schema: this uses a reserved schema keyword: `Set`
assert.equal(result.errors?.length, 1);
if (result.errors) {
let e = result.errors[0];
assert.ok(
e.message.includes('this uses a reserved schema keyword: `Set`')
);
assert.equal(e.offset, 188);
assert.equal(e.length, 3);
}

result.free();
});
});

Expand All @@ -56,26 +92,21 @@ suite('Validation RegEx Test Suite', () => {
result.free();
});

test('validate policy error "offset"', async () => {
const policy = readTestDataFile('offset', 'policy.cedar');
const schema = readTestDataFile('offset', 'cedarschema.json');
test('validate policy warning "impossible"', async () => {
const policy = readTestDataFile('impossible', 'policy.cedar');
const schema = readTestDataFile('impossible', 'cedarschema.json');

const result: cedar.ValidatePolicyResult = cedar.validatePolicySchemaJSON(
schema,
policy
);
assert.equal(result.success, false);
assert.equal(result.success, true);
assert.equal(result.warnings?.length, 1);

if (result.errors) {
// the types __cedar::internal::True and Long are not compatible\nfor policy `policy0`, both operands to a `==` expression must have compatible types. Types must be exactly equal to be compatible
let e: cedar.ValidateMessage = result.errors[0];
assert.ok(
e.message.startsWith(
'the types __cedar::internal::True and Long are not compatible'
)
);
assert.equal(e.offset, 44);
assert.equal(e.length, 9);
if (result.warnings) {
// for policy `policy0`, policy is impossible: the policy expression evaluates to false for all valid requests
let e: cedar.ValidateMessage = result.warnings[0];
assert.ok(e.message.includes('policy is impossible:'));
}

result.free();
Expand Down
17 changes: 14 additions & 3 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as vscode from 'vscode';
import * as cedar from 'vscode-cedar-wasm';
import {
addPolicyResultErrors,
addPolicyResultMessages,
addSyntaxDiagnosticErrors,
addValidationDiagnosticWarning,
determineRangeFromOffset,
Expand Down Expand Up @@ -253,13 +253,24 @@ export const validateCedarDoc = async (
policyText
);
}
if (policyResult.warnings) {
addPolicyResultMessages(
diagnostics,
policyResult.warnings,
policyText,
policyRange.effectRange,
policyRange.range.start.line,
true
);
}
if (policyResult.success === false && policyResult.errors) {
addPolicyResultErrors(
addPolicyResultMessages(
diagnostics,
policyResult.errors,
policyText,
policyRange.effectRange,
policyRange.range.start.line
policyRange.range.start.line,
false
);
}
policyResult.free();
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions testdata/reserved/__cedar.cedarschema
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error parsing schema: use of the reserved `__cedar` namespace
// Names containing `__cedar` (for example: `__cedar::A`, `A::__cedar`, or `A::__cedar::B`) are reserved
namespace __cedar {
entity foo;
}
5 changes: 5 additions & 0 deletions testdata/reserved/set.cedarschema
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error parsing schema: this uses a reserved schema keyword: `Set`
// Keywords such as `entity`, `extension`, `set` and `record` cannot be used as common type names
namespace NS {
type Set = Long;
}
26 changes: 13 additions & 13 deletions vscode-cedar-wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vscode-cedar-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "vscode-cedar-wasm"

version = "0.10.0"
version = "0.10.1"
edition = "2021"
description = "WASM bindgen bindings for cedar-policy 4.7.0"
description = "WASM bindgen bindings for cedar-policy 4.8.2"
license-file = "LICENSE"
homepage = "https://cedarpolicy.com"
repository = "https://github.com/cedar-policy/vscode-cedar"
Expand All @@ -30,9 +30,9 @@ serde_json = "1.0.96"
console_error_panic_hook = { version = "0.1.6", optional = true }

# cedar
cedar-policy = { version = "=4.7.0" }
cedar-policy-core = { version = "=4.7.0" }
cedar-policy-formatter = { version = "=4.7.0" }
cedar-policy = { version = "=4.8.2" }
cedar-policy-core = { version = "=4.8.2" }
cedar-policy-formatter = { version = "=4.8.2" }
miette = "7.2.0"

[dev-dependencies]
Expand Down
Loading
Loading