Skip to content
Merged
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
11 changes: 8 additions & 3 deletions bin/run-all-tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Run every automated test suite in the repository.
#
# Suites run in this order:
# 1. builder-frontend - Vitest unit tests (npm test)
# 1. builder-frontend - Vitest unit tests, then format and type checks
# 2. builder-api - JVM unit/integration tests (mvn test)
# 3. library-api - JVM unit/integration tests (mvn test)
# 4. examples - Node tests for the CRM examples (node --test)
Expand Down Expand Up @@ -40,7 +40,7 @@ Runs every automated test suite in the repository. Run it directly or as
Devbox on its own.

Suites:
builder-frontend builder-frontend Vitest tests (npm test)
builder-frontend builder-frontend Vitest tests, format check, type check
builder-api builder-api JVM tests (mvn test)
library-api library-api JVM tests (mvn test)
examples CRM example Node tests (node --test)
Expand Down Expand Up @@ -183,7 +183,12 @@ run_builder_frontend_suite() {
print_status "Installing builder-frontend dependencies..."
npm install
fi
npm test
# Run every check so one failure doesn't hide another.
local status=0
npm test || status=1
npm run format:check || status=1
npm run typecheck || status=1
exit "$status"
)
}

Expand Down
13 changes: 13 additions & 0 deletions builder-frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ It correctly bundles Solid in production mode and optimizes the build for the be
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

### `npm run format` and `npm run format:check`

Formats `src` with Prettier's defaults, or checks that it is formatted.

### `npm run typecheck`

Type-checks `src`, failing only when a file has more errors than
`typecheck-baseline.json` records for it. After fixing type errors, run
`npm run typecheck -- --update` to lower the baseline.

`devbox run test -- builder-frontend` runs the tests, the format check and the
type check, as CI does.

## Deployment

Learn more about deploying your application with the [documentations](https://vite.dev/guide/static-deploy.html)
Expand Down
19 changes: 19 additions & 0 deletions builder-frontend/package-lock.json

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

7 changes: 6 additions & 1 deletion builder-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "vitest run"
"test": "vitest run",
"format": "prettier --write src",
"format:check": "prettier --check src",
"typecheck": "node scripts/typecheck.mjs"
},
"dependencies": {
"@bpmn-io/feel-editor": "^2.7.1",
Expand Down Expand Up @@ -35,6 +38,8 @@
"@tailwindcss/postcss": "^4.1.8",
"@tailwindcss/vite": "^4.1.18",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.17.27",
"@types/lodash.debounce": "^4.0.9",
"autoprefixer": "^10.4.21",
"jsdom": "^30.0.1",
"postcss": "^8.5.4",
Expand Down
86 changes: 86 additions & 0 deletions builder-frontend/scripts/typecheck.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Type-check src against a per-file baseline of known errors.
//
// The codebase predates type checking, so `tsc` reports errors in files nobody
// has touched. This fails only when a file has more errors than its baseline,
// so new code is checked without first fixing every old error. After fixing
// errors, run `npm run typecheck -- --update` to lower the baseline.

import { execFileSync } from "node:child_process";
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

const root = fileURLToPath(new URL("..", import.meta.url));
const baselinePath = `${root}typecheck-baseline.json`;
const update = process.argv.includes("--update");

let output;
try {
output = execFileSync("node_modules/.bin/tsc", ["--noEmit", "-p", "."], {
cwd: root,
encoding: "utf8",
});
} catch (error) {
// tsc exits non-zero whenever it reports errors.
if (typeof error.stdout !== "string") throw error;
output = error.stdout;
}

// Group each error's lines (tsc continues a message on indented lines) by file.
const errors = new Map();
let current;
for (const line of output.split("\n")) {
const located = line.match(/^(.+?)\(\d+,\d+\): error TS\d+/);
const global = line.match(/^error TS\d+/);
if (located || global) {
const file = located ? located[1] : "(no file)";
current = [line];
errors.set(file, [...(errors.get(file) ?? []), current]);
} else if (current && line.startsWith(" ")) {
current.push(line);
}
}

const counts = Object.fromEntries(
[...errors].map(([file, list]) => [file, list.length]).sort(),
);
const total = Object.values(counts).reduce((sum, count) => sum + count, 0);

if (update) {
writeFileSync(baselinePath, `${JSON.stringify(counts, null, 2)}\n`);
console.log(
`Recorded ${total} known type errors in typecheck-baseline.json.`,
);
process.exit(0);
}

const baseline = existsSync(baselinePath)
? JSON.parse(readFileSync(baselinePath, "utf8"))
: {};
const worse = Object.keys(counts).filter(
(file) => counts[file] > (baseline[file] ?? 0),
);
const better = Object.keys(baseline).filter(
(file) => (counts[file] ?? 0) < baseline[file],
);

for (const file of worse) {
console.error(
`${file}: ${counts[file]} type errors, baseline allows ${baseline[file] ?? 0}`,
);
for (const lines of errors.get(file)) console.error(lines.join("\n"));
}
if (better.length > 0) {
console.log(
`Fewer type errors than the baseline in ${better.join(", ")}. ` +
"Run `npm run typecheck -- --update` to lock in the improvement.",
);
}
if (worse.length > 0) {
console.error(
"\nFix the new type errors above. Only lower the baseline, never raise it.",
);
process.exit(1);
}
console.log(
`Type check passed: ${total} type errors, none beyond the baseline.`,
);
10 changes: 7 additions & 3 deletions builder-frontend/src/api/publishedScreener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { env } from "@/config/environment";

const apiUrl = env.apiUrl;

export const fetchPublishedScreener = async (publishedScreenerId: string): Promise<PublishedScreener> => {
export const fetchPublishedScreener = async (
publishedScreenerId: string,
): Promise<PublishedScreener> => {
const url = apiUrl + "/published/screener/" + publishedScreenerId;
try {
const response = await fetch(url, {
Expand All @@ -24,8 +26,10 @@ export const fetchPublishedScreener = async (publishedScreenerId: string): Promi
}
};


export const evaluatePublishedScreener = async (publishedScreenerId: string, inputData: any): Promise<ScreenerResult> => {
export const evaluatePublishedScreener = async (
publishedScreenerId: string,
inputData: any,
): Promise<ScreenerResult> => {
const url = apiUrl + "/published/" + publishedScreenerId + "/evaluate";
try {
const response = await fetch(url, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Accessor, createEffect, onCleanup } from 'solid-js'
import { Content, createJSONEditor, JSONContent, JSONEditorPropsOptional, Mode, OnChange } from 'vanilla-jsoneditor'
import { Accessor, createEffect, onCleanup } from "solid-js";
import {
Content,
createJSONEditor,
JSONContent,
JSONEditorPropsOptional,
Mode,
OnChange,
} from "vanilla-jsoneditor";

const JSONEditorSolid = (props: JSONEditorPropsOptional) => {
let refContainer;
Expand All @@ -9,16 +16,16 @@ const JSONEditorSolid = (props: JSONEditorPropsOptional) => {
// create editor
refEditor = createJSONEditor({
target: refContainer,
props: {}
props: {},
});

onCleanup(() => {
// destroy editor
if (refEditor) {
refEditor.destroy()
refEditor = null
refEditor.destroy();
refEditor = null;
}
})
});
});

// update props
Expand All @@ -28,15 +35,21 @@ const JSONEditorSolid = (props: JSONEditorPropsOptional) => {
}
});

return <div ref={refContainer}/>;
}

return <div ref={refContainer} />;
};

const CheckJsonEditor = (
{ jsonContent, onValidJsonChange }:
{ jsonContent?: Accessor<Content>, onValidJsonChange: (json: JSONContent) => void }
) => {
const onChange = (updatedContent: Content, previousContent: Content, { contentErrors, patchResult }) => {
const CheckJsonEditor = ({
jsonContent,
onValidJsonChange,
}: {
jsonContent?: Accessor<Content>;
onValidJsonChange: (json: JSONContent) => void;
}) => {
const onChange = (
updatedContent: Content,
previousContent: Content,
{ contentErrors, patchResult },
) => {
if (contentErrors) {
return;
}
Expand All @@ -49,7 +62,7 @@ const CheckJsonEditor = (
jsonContent = { json: JSON.parse(updatedContent.text) };
}
onValidJsonChange(jsonContent);
}
};

return (
<div class="h-full">
Expand All @@ -61,5 +74,5 @@ const CheckJsonEditor = (
/>
</div>
);
}
};
export default CheckJsonEditor;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const EligibilityCheckTest = ({
eligibilityCheck: Accessor<EligibilityCheck>;
testEligibility: (
checkConfg: CheckConfig,
inputData: Record<string, any>
inputData: Record<string, any>,
) => Promise<OptionalBoolean>;
}) => {
const [checkConfig, setCheckConfig] = createSignal<CheckConfig>({
Expand Down Expand Up @@ -56,7 +56,7 @@ const EligibilityCheckTest = ({
onClick={async () => {
const result = await testEligibility(
checkConfig(),
currentJsonContent().json
currentJsonContent().json,
);
if (!result) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ it("warns about new benefits, saves only the screener copy, and resets a benefit
nextSteps: { eligible: { body: "Benefit instructions" } },
};
const field = {
benefitContent: { food: {}, removed: { eligible: { body: "Ignore removed" } } },
benefitContent: {
food: {},
removed: { eligible: { body: "Ignore removed" } },
},
};
const save = vi.fn();
const container = document.body.appendChild(document.createElement("div"));
Expand Down
Loading
Loading