Skip to content

docs: add validate-conditions.ts script#784

Open
theref wants to merge 1 commit into
nucypher:mainfrom
theref:add-validate-conditions-script
Open

docs: add validate-conditions.ts script#784
theref wants to merge 1 commit into
nucypher:mainfrom
theref:add-validate-conditions-script

Conversation

@theref
Copy link
Copy Markdown
Contributor

@theref theref commented Apr 29, 2026

Summary

Adds packages/taco/scripts/validate-conditions.ts: a CLI helper that runs a conditions.json file through ConditionExpression.fromObj and reports whether it satisfies the SDK's Zod schemas.

Hosting the script alongside the schemas it validates lets the TACo docs "Validating Conditions" page link to canonical infrastructure instead of an unrelated repo.

Context

Requested in @derekpierre's review on nucypher/taco-docs#12: "If the script is tested and works well, you can add it to the nucypher/taco-web repos. Once this URL is fixed, I can approve."

The script was previously hosted at theref/discord-taco-web/scripts/validate-conditions.ts.

Behaviour

  • Optional CLI arg for the conditions file path; defaults to ./conditions.json.
  • Exits 0 with the parsed conditionType on success.
  • Exits 1 on invalid input and writes the full Zod error to <input>.error.txt (intended for pasting into an LLM prompt for diagnosis).

Follow-up

Once this lands, validating-conditions.md in nucypher/taco-docs will be updated to point at the canonical script in this repo.

Test plan

  • pnpm tsx packages/taco/scripts/validate-conditions.ts <valid.json> → prints the parsed condition type, exits 0.
  • pnpm tsx packages/taco/scripts/validate-conditions.ts <invalid.json> → prints the Zod error, writes <invalid.json>.error.txt, exits 1.

Adds packages/taco/scripts/validate-conditions.ts: a CLI helper that
parses a conditions.json file through the SDK's ConditionExpression
and reports whether it satisfies the Zod schemas.

Intended for the "Validating Conditions" docs page, which previously
linked to a copy hosted in an unrelated repo. Hosting the script here
lets the docs reference canonical infrastructure that ships alongside
the schemas it validates.

Behaviour:
- Optional CLI arg for the conditions file path; defaults to
  ./conditions.json.
- Exits 1 on invalid input.
- Writes the full Zod error to <input>.error.txt so it can be pasted
  into an LLM prompt for diagnosis.
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 29, 2026

Deploy Preview for taco-nft-demo canceled.

Name Link
🔨 Latest commit 130a861
🔍 Latest deploy log https://app.netlify.com/projects/taco-nft-demo/deploys/69f1e22715e0520007848fa6

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 29, 2026

Deploy Preview for taco-demo canceled.

Name Link
🔨 Latest commit 130a861
🔍 Latest deploy log https://app.netlify.com/projects/taco-demo/deploys/69f1e2277afdcc00085ec16d

theref added a commit to nucypher/taco-docs that referenced this pull request Apr 29, 2026
The "Source" section of the Validating Conditions page previously
linked to a copy of validate-conditions.ts hosted in an unrelated
repo, with a note that the link would move once the script was
promoted into nucypher/taco-web.

Replace the placeholder link and accompanying caveat with the
canonical URL at nucypher/taco-web/packages/taco/scripts/. The
script is added in nucypher/taco-web#784.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.03%. Comparing base (e8f9098) to head (130a861).
⚠️ Report is 428 commits behind head on main.

Files with missing lines Patch % Lines
packages/taco/scripts/validate-conditions.ts 0.00% 28 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #784       +/-   ##
===========================================
+ Coverage   23.12%   87.03%   +63.90%     
===========================================
  Files          62       83       +21     
  Lines       10175     5806     -4369     
  Branches      260      201       -59     
===========================================
+ Hits         2353     5053     +2700     
+ Misses       7763      750     -7013     
+ Partials       59        3       -56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a TACo SDK-local CLI helper for validating a conditions.json file by parsing it through ConditionExpression.fromObj and reporting success/failure (including writing validation errors to a sidecar file).

Changes:

  • Add packages/taco/scripts/validate-conditions.ts CLI script to load and validate a conditions JSON file.
  • On validation failure, write error details to <input>.error.txt and exit non-zero.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,45 @@
#!/usr/bin/env npx tsx
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The hashbang #!/usr/bin/env npx tsx is not a valid/portable shebang: most kernels pass everything after /usr/bin/env as a single argument, so env will look for an executable literally named "npx tsx" and the script won’t be runnable when invoked directly. Consider either removing the shebang (since the documented invocation is via pnpm tsx ...) or switching to a portable form like using env -S to split arguments (and ensuring the repo’s supported platforms include it).

Suggested change
#!/usr/bin/env npx tsx

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +26
const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8');
const conditionsObj = JSON.parse(conditionsJson);

console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));

console.log('\n--- Validating with TACo SDK ---\n');

try {
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

Errors from readFileSync/JSON.parse (missing file, invalid JSON) occur before the try/catch, and the final main().catch(console.error) will log them but still exit with status 0. This contradicts the documented behavior of exiting 1 on invalid input. Wrap the file read/parse in the same try/catch (or set process.exitCode = 1 in the top-level catch) so any failure results in a non-zero exit status.

Suggested change
const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8');
const conditionsObj = JSON.parse(conditionsJson);
console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));
console.log('\n--- Validating with TACo SDK ---\n');
try {
try {
const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8');
const conditionsObj = JSON.parse(conditionsJson);
console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));
console.log('\n--- Validating with TACo SDK ---\n');

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +23
console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));

Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The PR description/test plan says the script prints the parsed conditionType on success, but the script currently always prints the full loaded conditions JSON (and additional status lines). If the docs are going to reference this as a canonical helper, consider minimizing default stdout to just the conditionType (and/or gating the full JSON dump behind a --verbose flag) so the output matches the documented behavior and is easier to script against.

Copilot uses AI. Check for mistakes.
}
}

main().catch(console.error);
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

If main() rejects, main().catch(console.error) logs the error but does not set a failing exit code, so CI/consumers will see a successful exit even though validation didn’t run. Set process.exitCode = 1 (or call process.exit(1)) in this catch handler after logging.

Suggested change
main().catch(console.error);
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

Copilot uses AI. Check for mistakes.
try {
const expr = ConditionExpression.fromObj(conditionsObj);
console.log('✅ Conditions are VALID according to TACo SDK!');
console.log('\nParsed condition type:', expr.condition.conditionType);
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.

Suggested change
console.log('\nParsed condition type:', expr.condition.conditionType);
console.log('\nParsed condition type:', expr.condition.value.conditionType);

@derekpierre derekpierre dismissed their stale review May 1, 2026 14:03

mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants