@topline-build/harness-mcp 0.9.15 → 0.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/artifact-starters.d.ts +9 -0
- package/dist/artifact-starters.js +27 -17
- package/dist/index.d.ts +6 -2
- package/dist/index.js +87 -14
- package/docs/generated/build-mcp-manifest.json +36 -7
- package/docs/generated/build-mcp-reference.md +23 -6
- package/package.json +2 -1
- package/templates/table-approvals-app/src/index.js +244 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable customer-visible Build MCP changes are recorded here. A source change is not a published package or customer release.
|
|
4
4
|
|
|
5
|
+
## 0.9.17 - 2026-11-16
|
|
6
|
+
|
|
7
|
+
- `platform_inspect_artifact_app`, when this computer is signed in, sends the bundle to Topline's preflight (`POST /api/harness/artifact-apps/preflight-bundle`). It runs the build's own local validation, such as `undeclared_package_import` for `react`, `esbuild` or `@aws-sdk/*`, and the manifest rules Topline applies on save, such as `tables[].operations` needing at least one operation. Each problem is listed under `problems`. `serverChecks` says whether the preflight ran (`passed`, `failed`, or `skipped:<reason>`), and `serverManifestValidationRequired` is false once it has. It never opens a browser sign-in.
|
|
8
|
+
- `platform_deploy_artifact_app` returns one `operationId`, the id `platform_wait_artifact_deploy` and `platform_deploy_operation` take: the build session's operation, or the task for a deploy outside a session. The worker task is `deployTaskId`, and the nested `deploy` record no longer repeats either id.
|
|
9
|
+
- `platform_init_artifact_app` has a `table-approvals-app` starter: a request form, "My requests" and an approver queue over company tables, written through server table SQL (`serverTables: true`) with a copyable `tablesSql()` helper and an app-owned approvers table. It declares no `tables[]`, so viewers can't list rows through a browser table route. Before its tables exist the page shows a setup state instead of failing smoke.
|
|
10
|
+
- The `cache-warmed-multi-source-dashboard` starter now says it needs the Redis live cache, and its first step is to check `platform_capability_status` and use `precomputed-s3-report` where `families.redis` is `not_supported`.
|
|
11
|
+
|
|
12
|
+
## 0.9.16 - 2026-11-11
|
|
13
|
+
|
|
14
|
+
- `platform_deploy_artifact_app` runs inspect's manifest and `node --check` checks and refuses with `artifact_package_not_ready`, naming each problem's code and file, before it uploads anything or spends build budget. (Data-binding findings stay inspect-only, since a leftover build file can trip them.)
|
|
15
|
+
- `node --check` no longer reports an ES module file as a syntax error on Node versions that check it as CommonJS ("Cannot use import statement outside a module").
|
|
16
|
+
- Inside a build session, a deploy that passes `projectId` is refused locally with `build_session_project_id_not_allowed` instead of reaching Topline as a retryable server error.
|
|
17
|
+
- A deploy cancelled because its build session was closed (`artifact_deploy_failed:build_session_cancelled`) says to start a new session and deploy again, not to fix the source.
|
|
18
|
+
- `javascript_syntax_error` details no longer end in a stray carriage return on Windows.
|
|
19
|
+
|
|
5
20
|
## 0.9.15 - 2026-11-11
|
|
6
21
|
|
|
7
22
|
- `platform_inspect_artifact_app` runs `node --check` on each `.js`, `.mjs` and `.cjs` source file, so a syntax error makes `packageReady` false with a `javascript_syntax_error` problem naming the file and line, instead of failing the build after deploy.
|
|
@@ -26,6 +26,13 @@ export type ArtifactStarter = {
|
|
|
26
26
|
routes: ArtifactStarterRoute[];
|
|
27
27
|
/** What the recipe adds on top of the scaffold, in the order to do it. */
|
|
28
28
|
nextSteps: string[];
|
|
29
|
+
/**
|
|
30
|
+
* A complete app source shipped in templates/<id>/src/index.js instead of the
|
|
31
|
+
* generated placeholder handler; "__ARTIFACT_TITLE__" is replaced with the title.
|
|
32
|
+
*/
|
|
33
|
+
template?: boolean;
|
|
34
|
+
/** Extra top-level manifest fields the starter needs (for example serverTables). */
|
|
35
|
+
manifest?: Record<string, unknown>;
|
|
29
36
|
};
|
|
30
37
|
export declare const ARTIFACT_STARTERS: ArtifactStarter[];
|
|
31
38
|
export declare const ARTIFACT_STARTER_IDS: string[];
|
|
@@ -42,5 +49,7 @@ export declare function artifactStarterRecipe(starter: ArtifactStarter): {
|
|
|
42
49
|
pluginPath: string;
|
|
43
50
|
nextSteps: string[];
|
|
44
51
|
};
|
|
52
|
+
/** The shipped source of a template starter, with its title filled in. */
|
|
53
|
+
export declare function artifactStarterTemplateSource(starter: ArtifactStarter, title: string): Promise<string>;
|
|
45
54
|
/** Source for src/index.js: one handler serving the page and a placeholder per declared route. */
|
|
46
55
|
export declare function artifactStarterSource(starter: ArtifactStarter, title: string): string;
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Catalog-backed starters for platform_init_artifact_app.
|
|
3
|
-
*
|
|
4
|
-
* Each starter mirrors the route shape of one golden example in the Build
|
|
5
|
-
* cookbook (skills/build-topline-artifact-apps/examples/<id>/), so a new app
|
|
6
|
-
* starts with the recipe's page and private routes instead of a blank page.
|
|
7
|
-
* The scaffold is dependency-free Node and serves placeholder answers only:
|
|
8
|
-
* it never declares datasets, source bindings, secret bindings or Bedrock env,
|
|
9
|
-
* because those need the customer's own tables, sources and approved secrets.
|
|
10
|
-
* The platform itself serves /_artifact/data/* and /_artifact/knowledge/*, and
|
|
11
|
-
* only for a declared dataset, binding or grant, so app code never sees those
|
|
12
|
-
* requests. A starter's data route is therefore not a manifest route or a
|
|
13
|
-
* handler: the page shows it as not connected and never fetches it, so a
|
|
14
|
-
* fresh deploy's smoke check stays healthy instead of failing on a 404.
|
|
15
|
-
* Its structured tests are labelled scaffold checks, not proof of behavior.
|
|
16
|
-
*/
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
17
2
|
export const ARTIFACT_STARTERS = [
|
|
18
3
|
{
|
|
19
4
|
id: "bounded-bedrock-assistant",
|
|
@@ -32,9 +17,10 @@ export const ARTIFACT_STARTERS = [
|
|
|
32
17
|
{
|
|
33
18
|
id: "cache-warmed-multi-source-dashboard",
|
|
34
19
|
kind: "dashboard",
|
|
35
|
-
summary: "Dashboard over a live dataset whose cache a schedule keeps warm.",
|
|
20
|
+
summary: "Dashboard over a live dataset whose cache a schedule keeps warm. Needs the Redis live cache: check platform_capability_status first, and where families.redis is not_supported use precomputed-s3-report instead.",
|
|
36
21
|
routes: [{ path: "/_artifact/data/branch-service-summary", note: "Placeholder for the recipe's live dataset." }],
|
|
37
22
|
nextSteps: [
|
|
23
|
+
"Call platform_capability_status: if families.redis is not_supported, this recipe's cache warming can't run on this account; start again from precomputed-s3-report.",
|
|
38
24
|
"Find your own tables with the Workspace data catalog, then add the recipe's datasets[] and refreshSchedules[] with your SQL.",
|
|
39
25
|
"Once the dataset serves the route, fetch it from the page in place of the not-connected notice and replace its scaffold check."
|
|
40
26
|
]
|
|
@@ -93,6 +79,24 @@ export const ARTIFACT_STARTERS = [
|
|
|
93
79
|
],
|
|
94
80
|
nextSteps: ["The recipe uses the python-api template; keep this Node scaffold or port it, but keep every route under /_artifact/api/."]
|
|
95
81
|
},
|
|
82
|
+
{
|
|
83
|
+
id: "table-approvals-app",
|
|
84
|
+
kind: "tool",
|
|
85
|
+
summary: "Requests and approvals over company tables: a request form, \"My requests\", and an approver queue, all through server table SQL with no tables[] browser route.",
|
|
86
|
+
routes: [
|
|
87
|
+
{ path: "/_artifact/api/requests", note: "GET the viewer's requests (and the approver queue); POST a new request." },
|
|
88
|
+
{ path: "/_artifact/api/decisions", method: "POST", note: "An approver approves or rejects the version they saw." }
|
|
89
|
+
],
|
|
90
|
+
nextSteps: [
|
|
91
|
+
"Create the two tables with platform_run_artifact_workspace_sql (scope company), using the CREATE TABLE statements in the recipe; rename them to fit (for example company_data.time_off_requests) and update REQUESTS and APPROVERS in src/index.js.",
|
|
92
|
+
"Insert the approvers' emails into the approvers table (active true). There are no platform roles; this table is the app's role list.",
|
|
93
|
+
"Add your request fields (dates, amounts) as columns, in the form, and in the insert; every value comes back from server SQL as a string.",
|
|
94
|
+
"Drafts can only read through server SQL. To try submit and decide on a draft, set previewWrites: true, knowing it changes real rows; otherwise check writes on the live app after a person publishes it.",
|
|
95
|
+
"Keep tables[] out of the manifest: a tables[] binding would let every viewer list the rows directly."
|
|
96
|
+
],
|
|
97
|
+
template: true,
|
|
98
|
+
manifest: { serverTables: true }
|
|
99
|
+
},
|
|
96
100
|
{
|
|
97
101
|
id: "viewer-scoped-customer-portal",
|
|
98
102
|
kind: "dashboard",
|
|
@@ -129,6 +133,12 @@ export function artifactStarterRecipe(starter) {
|
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
135
|
const escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[char]));
|
|
136
|
+
/** The shipped source of a template starter, with its title filled in. */
|
|
137
|
+
export async function artifactStarterTemplateSource(starter, title) {
|
|
138
|
+
const source = await readFile(new URL(`../templates/${starter.id}/src/index.js`, import.meta.url), "utf8");
|
|
139
|
+
// JSON.stringify yields a valid JS string literal; slice off its quotes to sit inside the existing ones.
|
|
140
|
+
return source.replace("__ARTIFACT_TITLE__", () => JSON.stringify(title).slice(1, -1));
|
|
141
|
+
}
|
|
132
142
|
/** Source for src/index.js: one handler serving the page and a placeholder per declared route. */
|
|
133
143
|
export function artifactStarterSource(starter, title) {
|
|
134
144
|
const safeTitle = escapeHtml(title);
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ type ToolProgressReporter = (progress: number, message: string) => void | Promis
|
|
|
42
42
|
export type McpSurface = "build" | "topline" | "harness";
|
|
43
43
|
export declare const DEFAULT_MCP_PROTOCOL_VERSION = "2025-11-25";
|
|
44
44
|
export declare const BUILD_MCP_SERVER_NAME = "topline-build-stdio";
|
|
45
|
-
export declare const HARNESS_MCP_VERSION = "0.9.
|
|
45
|
+
export declare const HARNESS_MCP_VERSION = "0.9.17";
|
|
46
46
|
export declare const DEFAULT_OAUTH_SCOPES: readonly string[];
|
|
47
47
|
/** The Topline server's scopes: Build and Workspace. Consent shows what the seat allows. */
|
|
48
48
|
export declare const TOPLINE_OAUTH_SCOPES: readonly string[];
|
|
@@ -88,6 +88,7 @@ export declare function callHarnessTool(opts: HarnessMcpStdioOptions, name: stri
|
|
|
88
88
|
}): Promise<CallToolResult>;
|
|
89
89
|
export declare function deployArtifactApp(opts: HarnessMcpStdioOptions, input: Record<string, unknown>, onProgress?: ToolProgressReporter): Promise<{
|
|
90
90
|
operationId: string | null;
|
|
91
|
+
deployTaskId: string | null;
|
|
91
92
|
bundle: {
|
|
92
93
|
fileCount: number;
|
|
93
94
|
byteCount: number;
|
|
@@ -95,7 +96,9 @@ export declare function deployArtifactApp(opts: HarnessMcpStdioOptions, input: R
|
|
|
95
96
|
excluded: string[];
|
|
96
97
|
};
|
|
97
98
|
create: unknown;
|
|
98
|
-
deploy:
|
|
99
|
+
deploy: {
|
|
100
|
+
[x: string]: unknown;
|
|
101
|
+
};
|
|
99
102
|
sessionId?: string | undefined;
|
|
100
103
|
ok: boolean;
|
|
101
104
|
artifactId: string;
|
|
@@ -143,6 +146,7 @@ export declare function inspectArtifactApp(opts: HarnessMcpStdioOptions, input:
|
|
|
143
146
|
detail: string;
|
|
144
147
|
}[];
|
|
145
148
|
serverManifestValidationRequired: boolean;
|
|
149
|
+
serverChecks: string;
|
|
146
150
|
appDir: string;
|
|
147
151
|
platformAppDir: string;
|
|
148
152
|
manifest: {
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import { gzipSync } from "node:zlib";
|
|
10
10
|
import { externalBuildHelperTools, EXTERNAL_BUILD_FORWARD_TOOLS, EXTERNAL_BUILD_SESSION_FORWARD_TOOLS, EXTERNAL_BUILD_SESSION_TOOLS } from "./build-session-tools.js";
|
|
11
11
|
import { domainHelperTools, DOMAIN_FORWARD_TOOLS, DOMAIN_ERROR_CODES } from "./domain-tools.js";
|
|
12
|
-
import { ARTIFACT_STARTER_IDS, artifactStarterAppRoutes, artifactStarterRecipe, artifactStarterSource, findArtifactStarter } from "./artifact-starters.js";
|
|
12
|
+
import { ARTIFACT_STARTER_IDS, artifactStarterAppRoutes, artifactStarterRecipe, artifactStarterSource, artifactStarterTemplateSource, findArtifactStarter } from "./artifact-starters.js";
|
|
13
13
|
import { boundedTransfer, extractArtifactSourceArchive, MAX_SOURCE_ARCHIVE_BYTES, safeSourcePath } from "./source-checkout.js";
|
|
14
14
|
import { Server as McpServer } from "@modelcontextprotocol/sdk/server/index.js";
|
|
15
15
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -19,7 +19,7 @@ const MCP_SURFACES = ["build", "topline", "harness"];
|
|
|
19
19
|
export const DEFAULT_MCP_PROTOCOL_VERSION = "2025-11-25";
|
|
20
20
|
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
21
21
|
export const BUILD_MCP_SERVER_NAME = "topline-build-stdio";
|
|
22
|
-
export const HARNESS_MCP_VERSION = "0.9.
|
|
22
|
+
export const HARNESS_MCP_VERSION = "0.9.17";
|
|
23
23
|
export const DEFAULT_OAUTH_SCOPES = Object.freeze(["harness:artifact:read", "harness:artifact:write", "harness:artifact:deploy", "harness:artifact:delete"]);
|
|
24
24
|
/** The Topline server's scopes: Build and Workspace. Consent shows what the seat allows. */
|
|
25
25
|
export const TOPLINE_OAUTH_SCOPES = Object.freeze([
|
|
@@ -936,6 +936,14 @@ export async function deployArtifactApp(opts, input, onProgress) {
|
|
|
936
936
|
.digest("hex");
|
|
937
937
|
await onProgress?.(0.2, "Packaging local artifact app");
|
|
938
938
|
const bundle = await packArtifactAppDirectory(absoluteAppDir, platformAppDir === "." ? "" : platformAppDir);
|
|
939
|
+
// Round 13 R4: a package inspect says isn't ready fails the build the same way, after spending
|
|
940
|
+
// budget and a minute; refuse it here, before anything is uploaded.
|
|
941
|
+
// Only checks that can't be a stale or unrelated file (manifest fields and syntax errors) block a deploy;
|
|
942
|
+
// inspect still lists data-binding findings, which a leftover build output can trip.
|
|
943
|
+
const problems = (await localPreflightProblems(absoluteAppDir, manifest)).filter((problem) => problem.code === "invalid_artifact_app_manifest");
|
|
944
|
+
problems.push(...await javascriptSyntaxProblems(absoluteAppDir));
|
|
945
|
+
if (problems.length)
|
|
946
|
+
throw new Error(`artifact_package_not_ready:${problems.slice(0, 5).map((problem) => `${problem.code} ${problem.path}`).join("; ")}`);
|
|
939
947
|
const expectedBundleSha256 = optionalString(input, "expectedBundleSha256")?.toLowerCase();
|
|
940
948
|
if (expectedBundleSha256 && bundle.sha256 !== expectedBundleSha256) {
|
|
941
949
|
throw new Error("artifact_app_bundle_changed_after_inspection");
|
|
@@ -952,6 +960,9 @@ export async function deployArtifactApp(opts, input, onProgress) {
|
|
|
952
960
|
.filter(([, value]) => !value).map(([name]) => name);
|
|
953
961
|
if (missing.length)
|
|
954
962
|
throw new Error(`build_session_deployment_arguments_required:${missing.join(",")}`);
|
|
963
|
+
// Round 13 R7: the session already belongs to its artifact (and project); Topline refuses projectId here.
|
|
964
|
+
if (optionalString(input, "projectId"))
|
|
965
|
+
throw new Error("build_session_project_id_not_allowed");
|
|
955
966
|
const session = asRecord(await callHostedBuildTool(opts, "platform_read_build_session", { sessionId }));
|
|
956
967
|
// The server resolves a repeated operation key before checking current
|
|
957
968
|
// version/source. Do not reject a lost-response retry using the newer read.
|
|
@@ -1003,8 +1014,13 @@ export async function deployArtifactApp(opts, input, onProgress) {
|
|
|
1003
1014
|
});
|
|
1004
1015
|
await onProgress?.(1, "Completed trusted draft deployment");
|
|
1005
1016
|
const deployedRecord = asRecord(deployed);
|
|
1006
|
-
|
|
1007
|
-
|
|
1017
|
+
// W3 (2026-11-16): one id. operationId is the deploy operation platform_wait_artifact_deploy and
|
|
1018
|
+
// platform_deploy_operation take (a session's operation, or the task for a sessionless deploy);
|
|
1019
|
+
// the worker task is only deployTaskId, and the nested deploy record no longer repeats either.
|
|
1020
|
+
const operationId = typeof deployedRecord.operationId === "string" ? deployedRecord.operationId
|
|
1021
|
+
: typeof deployedRecord.taskId === "string" ? deployedRecord.taskId : null;
|
|
1022
|
+
const deployTaskId = typeof deployedRecord.taskId === "string" ? deployedRecord.taskId : null;
|
|
1023
|
+
const { operationId: _operationId, taskId: _taskId, ...deployRecord } = deployedRecord;
|
|
1008
1024
|
return {
|
|
1009
1025
|
ok: true,
|
|
1010
1026
|
artifactId,
|
|
@@ -1013,6 +1029,7 @@ export async function deployArtifactApp(opts, input, onProgress) {
|
|
|
1013
1029
|
clientRequestId,
|
|
1014
1030
|
...(sessionId ? { sessionId } : {}),
|
|
1015
1031
|
operationId,
|
|
1032
|
+
deployTaskId,
|
|
1016
1033
|
bundle: {
|
|
1017
1034
|
fileCount: bundle.fileCount,
|
|
1018
1035
|
byteCount: bundle.byteCount,
|
|
@@ -1020,7 +1037,7 @@ export async function deployArtifactApp(opts, input, onProgress) {
|
|
|
1020
1037
|
excluded: bundle.excluded
|
|
1021
1038
|
},
|
|
1022
1039
|
create: created,
|
|
1023
|
-
deploy:
|
|
1040
|
+
deploy: deployRecord
|
|
1024
1041
|
};
|
|
1025
1042
|
}
|
|
1026
1043
|
async function fetchBuildTransfer(opts, advertisedPath, expectedPath, sha256, maxBytes, expectedSize, revision) {
|
|
@@ -1155,13 +1172,20 @@ export async function inspectArtifactApp(opts, input) {
|
|
|
1155
1172
|
const bundle = await packArtifactAppDirectory(absoluteAppDir, platformAppDir === "." ? "" : platformAppDir);
|
|
1156
1173
|
const problems = await localPreflightProblems(absoluteAppDir, manifest);
|
|
1157
1174
|
problems.push(...await javascriptSyntaxProblems(absoluteAppDir));
|
|
1175
|
+
const server = await serverPreflightProblems(opts, bundle.body, platformAppDir);
|
|
1176
|
+
// A rule both sides check (a data binding with no dataset) is listed once, in inspect's words.
|
|
1177
|
+
const reported = new Set(problems.map((problem) => `${problem.code}\0${problem.path}`));
|
|
1178
|
+
for (const problem of server.problems)
|
|
1179
|
+
if (!reported.has(`${problem.code}\0${problem.path}`))
|
|
1180
|
+
problems.push(problem);
|
|
1158
1181
|
const warnings = await renderedTextRuleWarnings(absoluteAppDir);
|
|
1159
1182
|
return {
|
|
1160
1183
|
ok: true,
|
|
1161
1184
|
packageReady: problems.length === 0,
|
|
1162
1185
|
problems,
|
|
1163
1186
|
warnings,
|
|
1164
|
-
serverManifestValidationRequired:
|
|
1187
|
+
serverManifestValidationRequired: !server.checks.startsWith("passed") && !server.checks.startsWith("failed"),
|
|
1188
|
+
serverChecks: server.checks,
|
|
1165
1189
|
appDir: workspaceAppDir,
|
|
1166
1190
|
platformAppDir,
|
|
1167
1191
|
manifest: {
|
|
@@ -1188,6 +1212,43 @@ export async function inspectArtifactApp(opts, input) {
|
|
|
1188
1212
|
: "Call platform_deploy_artifact_app with the same appDir and expectedBundleSha256 set to bundle.sha256 when this local package is ready to deploy."
|
|
1189
1213
|
};
|
|
1190
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* W3 (MCP friction 2026-11-16): inspect said packageReady, then the build failed LOCAL_VALIDATION
|
|
1217
|
+
* (undeclared_package_import for react, esbuild, @aws-sdk/*) or the server refused the manifest
|
|
1218
|
+
* (tables[].operations: []). Rather than copy those rules here, send the same bundle to Topline's
|
|
1219
|
+
* preflight, which runs the build's own validation function and the server's manifest validator.
|
|
1220
|
+
* Never opens a browser sign-in: without a saved sign-in this is skipped and says so.
|
|
1221
|
+
*/
|
|
1222
|
+
async function serverPreflightProblems(opts, body, platformAppDir) {
|
|
1223
|
+
if (!servesBuild(opts))
|
|
1224
|
+
return { checks: "skipped:no_build_surface", problems: [] };
|
|
1225
|
+
const bearer = await getBearerTokenWithoutSignIn(opts).catch(() => null);
|
|
1226
|
+
if (!bearer)
|
|
1227
|
+
return { checks: "skipped:not_signed_in", problems: [] };
|
|
1228
|
+
try {
|
|
1229
|
+
const payload = asRecord(await fetchJson(opts, `${artifactAppsPath(opts)}/preflight-bundle`, {
|
|
1230
|
+
method: "POST",
|
|
1231
|
+
headers: {
|
|
1232
|
+
authorization: `Bearer ${bearer}`,
|
|
1233
|
+
"content-type": "application/gzip",
|
|
1234
|
+
"MCP-Protocol-Version": opts.protocolVersion,
|
|
1235
|
+
"x-platform-app-dir": platformAppDir
|
|
1236
|
+
},
|
|
1237
|
+
body: body
|
|
1238
|
+
}));
|
|
1239
|
+
const problems = (Array.isArray(payload.problems) ? payload.problems : []).filter(isRecord).map((problem) => ({
|
|
1240
|
+
code: typeof problem.code === "string" ? problem.code : "server_preflight_problem",
|
|
1241
|
+
path: typeof problem.path === "string" ? problem.path : "",
|
|
1242
|
+
detail: typeof problem.detail === "string" ? problem.detail : String(problem.code ?? "")
|
|
1243
|
+
}));
|
|
1244
|
+
return { checks: problems.length ? "failed" : "passed", problems };
|
|
1245
|
+
}
|
|
1246
|
+
catch (error) {
|
|
1247
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1248
|
+
// An older Topline has no preflight route (404); anything else is reported, not fatal.
|
|
1249
|
+
return { checks: /^platform_harness_http_error:404:/.test(message) ? "skipped:server_without_preflight" : "skipped:request_failed", problems: [] };
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1191
1252
|
const PREFLIGHT_SCAN_EXTENSIONS = new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".html", ".json", ".py", ".txt"]);
|
|
1192
1253
|
const PREFLIGHT_SKIP_DIRS = new Set(["node_modules", ".git", ".next", ".vite", ".turbo", ".cache"]);
|
|
1193
1254
|
/**
|
|
@@ -1288,9 +1349,13 @@ export async function javascriptSyntaxProblems(appDir) {
|
|
|
1288
1349
|
const stderr = await nodeCheck(file);
|
|
1289
1350
|
if (!stderr || !/SyntaxError/.test(stderr))
|
|
1290
1351
|
continue;
|
|
1352
|
+
// Round 13 review: an ES module file checked as CommonJS (older Node, no "type": "module") isn't
|
|
1353
|
+
// a syntax error the build hits; only real syntax errors count.
|
|
1354
|
+
if (/outside a module|Unexpected token 'export'|Cannot use 'import\.meta'/.test(stderr))
|
|
1355
|
+
continue;
|
|
1291
1356
|
const rel = path.relative(appDir, file).replaceAll("\\", "/");
|
|
1292
1357
|
const line = new RegExp(`${file.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:(\\d+)`).exec(stderr)?.[1] ?? null;
|
|
1293
|
-
const message = /SyntaxError:[^\n]*/.exec(stderr)?.[0]?.slice(0, 200) ?? "SyntaxError";
|
|
1358
|
+
const message = /SyntaxError:[^\r\n]*/.exec(stderr)?.[0]?.slice(0, 200) ?? "SyntaxError";
|
|
1294
1359
|
problems.push({ code: "javascript_syntax_error", path: line ? `${rel}:${line}` : rel, detail: `${rel}${line ? ` line ${line}` : ""}: ${message}` });
|
|
1295
1360
|
if (problems.length >= 10)
|
|
1296
1361
|
break;
|
|
@@ -1548,11 +1613,12 @@ export async function initArtifactApp(opts, input) {
|
|
|
1548
1613
|
],
|
|
1549
1614
|
sourceBindings: [],
|
|
1550
1615
|
env: ["ARTIFACT_ID", "ARTIFACT_VERSION_ID", "ARTIFACT_MANIFEST_URI", "PLATFORM_ARTIFACT_ID", "PLATFORM_ARTIFACT_VERSION_ID", "PLATFORM_ARTIFACT_MANIFEST_URI"],
|
|
1551
|
-
viewerPolicy: "private"
|
|
1616
|
+
viewerPolicy: "private",
|
|
1617
|
+
...(starter?.manifest ?? {})
|
|
1552
1618
|
};
|
|
1553
1619
|
const packageJson = { name: manifestId, private: true, type: "module", main: "src/index.js", scripts: { build: "node src/index.js --build", test: "node src/index.js --test" } };
|
|
1554
1620
|
const safeTitle = title.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[char]));
|
|
1555
|
-
const source = starter ? artifactStarterSource(starter, title) : `import { mkdirSync, writeFileSync } from "node:fs";\nimport path from "node:path";\n\nconst page = ${JSON.stringify(`<!doctype html><html><body><main data-platform-artifact-root><h1>${safeTitle}</h1><p>Ready.</p></main></body></html>`)};\n\nexport function artifactApp(_req, res) {\n res.setHeader("content-type", "text/html; charset=utf-8");\n res.end(page);\n}\n\nif (process.argv.includes("--build")) {\n mkdirSync("dist", { recursive: true });\n writeFileSync(path.join("dist", "index.html"), page, "utf8");\n}\n\nif (process.argv.includes("--test") && process.argv.includes("--artifact-tests-json")) {\n console.log(JSON.stringify({ tests: [{ description: "Scaffold check: the artifact renders a visible app root.", required: true, status: "passed", summary: "Generated starter check; not proof of implemented behavior.", evidence: { selector: "data-platform-artifact-root", scaffold: true } }] }));\n} else if (process.argv.includes("--build") || process.argv.includes("--test")) {\n console.log("artifact app template ok");\n}\n`;
|
|
1621
|
+
const source = starter?.template ? await artifactStarterTemplateSource(starter, title) : starter ? artifactStarterSource(starter, title) : `import { mkdirSync, writeFileSync } from "node:fs";\nimport path from "node:path";\n\nconst page = ${JSON.stringify(`<!doctype html><html><body><main data-platform-artifact-root><h1>${safeTitle}</h1><p>Ready.</p></main></body></html>`)};\n\nexport function artifactApp(_req, res) {\n res.setHeader("content-type", "text/html; charset=utf-8");\n res.end(page);\n}\n\nif (process.argv.includes("--build")) {\n mkdirSync("dist", { recursive: true });\n writeFileSync(path.join("dist", "index.html"), page, "utf8");\n}\n\nif (process.argv.includes("--test") && process.argv.includes("--artifact-tests-json")) {\n console.log(JSON.stringify({ tests: [{ description: "Scaffold check: the artifact renders a visible app root.", required: true, status: "passed", summary: "Generated starter check; not proof of implemented behavior.", evidence: { selector: "data-platform-artifact-root", scaffold: true } }] }));\n} else if (process.argv.includes("--build") || process.argv.includes("--test")) {\n console.log("artifact app template ok");\n}\n`;
|
|
1556
1622
|
await Promise.all([
|
|
1557
1623
|
writeFile(path.join(absoluteAppDir, "artifact-app.json"), `${JSON.stringify(manifest, null, 2)}\n`, { flag: "wx" }),
|
|
1558
1624
|
writeFile(path.join(absoluteAppDir, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`, { flag: "wx" }),
|
|
@@ -2071,7 +2137,7 @@ const BUILD_MCP_TOOLS = [
|
|
|
2071
2137
|
},
|
|
2072
2138
|
{
|
|
2073
2139
|
name: "platform_deploy_artifact_app",
|
|
2074
|
-
description: "Package a local artifact app directory, upload it, deploy a private draft, and return status.",
|
|
2140
|
+
description: "Package a local artifact app directory, upload it, deploy a private draft, and return status. It runs platform_inspect_artifact_app's manifest and JavaScript syntax checks first and refuses with artifact_package_not_ready, before uploading or spending budget, while any of those problems remain. Inside a build session, leave projectId out.",
|
|
2075
2141
|
annotations: mcpToolAnnotations("platform_deploy_artifact_app", { readOnly: false, openWorld: true }),
|
|
2076
2142
|
inputSchema: {
|
|
2077
2143
|
type: "object",
|
|
@@ -2099,7 +2165,8 @@ const BUILD_MCP_TOOLS = [
|
|
|
2099
2165
|
artifactId: { type: "string" },
|
|
2100
2166
|
artifactVersionId: { type: "string" },
|
|
2101
2167
|
clientRequestId: { type: "string" },
|
|
2102
|
-
operationId: { type: ["string", "null"] },
|
|
2168
|
+
operationId: { type: ["string", "null"], description: "The one deploy id: pass it to platform_wait_artifact_deploy and platform_deploy_operation." },
|
|
2169
|
+
deployTaskId: { type: ["string", "null"], description: "The worker task that ran the deploy, for logs only. Not an operation id." },
|
|
2103
2170
|
bundle: { type: "object" },
|
|
2104
2171
|
create: { type: "object" },
|
|
2105
2172
|
deploy: { type: "object" }
|
|
@@ -2109,7 +2176,7 @@ const BUILD_MCP_TOOLS = [
|
|
|
2109
2176
|
},
|
|
2110
2177
|
{
|
|
2111
2178
|
name: "platform_inspect_artifact_app",
|
|
2112
|
-
description: "Inspect local artifact paths and package boundaries without
|
|
2179
|
+
description: "Inspect local artifact paths and package boundaries without creating a remote draft, building or spending anything. Runs the manifest and data-binding checks Topline's build would fail (datasets[].name and route, routes[].path, ./_artifact/data/<name> references with no matching dataset) and a node --check of each .js/.mjs/.cjs file (javascript_syntax_error with file and line). When this computer is signed in to Topline, it also sends the bundle to Topline's preflight, which runs the build's own local validation (undeclared_package_import and the rest) and the manifest rules the server applies on save; serverChecks says whether that ran. packageReady is false and problems lists each one until they are fixed. warnings lists static text the build's page-text rules would refuse if the page shows it.",
|
|
2113
2180
|
annotations: mcpToolAnnotations("platform_inspect_artifact_app", { readOnly: true }),
|
|
2114
2181
|
inputSchema: {
|
|
2115
2182
|
type: "object",
|
|
@@ -2124,7 +2191,8 @@ const BUILD_MCP_TOOLS = [
|
|
|
2124
2191
|
packageReady: { type: "boolean" },
|
|
2125
2192
|
problems: { type: "array", items: { type: "object" }, description: "Checks Topline's build would fail: each has code, path (manifest field or file, with :line for javascript_syntax_error) and detail. packageReady is false while any remain." },
|
|
2126
2193
|
warnings: { type: "array", items: { type: "object" }, description: "Static text that matches a rule Topline's render smoke applies to the page (rendered_text_rule:sample_or_mock_data_text), with the file and phrase. The build fails only if the rendered page shows it." },
|
|
2127
|
-
serverManifestValidationRequired: { type: "boolean" },
|
|
2194
|
+
serverManifestValidationRequired: { type: "boolean", description: "True when Topline's preflight did not run (see serverChecks), so the server's manifest rules and the build's local validation are still unchecked." },
|
|
2195
|
+
serverChecks: { type: "string", description: "passed, failed (its problems are in problems), or skipped:<reason> (not signed in, an older Topline without the preflight, or the request failed)." },
|
|
2128
2196
|
appDir: { type: "string" },
|
|
2129
2197
|
platformAppDir: { type: "string" },
|
|
2130
2198
|
manifest: { type: "object" },
|
|
@@ -2573,6 +2641,9 @@ const BUILD_MCP_RECOVERY_ERROR_VALUES = {
|
|
|
2573
2641
|
artifact_app_scaffold_starter_shape_conflict: { retryable: false, recoveryAction: "A starter scaffolds the single shape; leave shape out or set it to single." },
|
|
2574
2642
|
// Stale preconditions: the same input can never succeed, whatever HTTP status an older Topline sends.
|
|
2575
2643
|
artifact_version_conflict: { retryable: false, recoveryAction: "The session moved to a newer version. Read the session (platform_read_build_session). A build session always starts from the app's current version; Build MCP can't check out an older saved version, so to go back, deploy source you saved before (or ask the coding agent in Topline to go back to version N). For a refused deploy: keep your local edits, run platform_inspect_artifact_app again, then deploy with the current artifactVersionId and the new inspectedSourceHash. For a refused validation request: don't deploy again. Wait for the current version's deploy to settle (platform_deploy_operation), run its checks and smoke, prepare it with platform_prepare_artifact_validation, then call platform_request_artifact_validation with that prepared evidence." },
|
|
2644
|
+
artifact_package_not_ready: { retryable: false, recoveryAction: "platform_inspect_artifact_app reports problems Topline's build would fail on (named after the code, with file and line), so nothing was uploaded or spent. Fix them, run platform_inspect_artifact_app until packageReady is true, then deploy with the new expectedBundleSha256." },
|
|
2645
|
+
build_session_project_id_not_allowed: { retryable: false, recoveryAction: "Inside a build session the draft already belongs to the session's artifact and project. Leave projectId out and call again." },
|
|
2646
|
+
"artifact_deploy_failed:build_session_cancelled": { retryable: false, recoveryAction: "This deploy was cancelled because its build session was closed before it finished; the source wasn't at fault. Start a new build session for this artifact, then inspect and deploy again." },
|
|
2576
2647
|
build_session_deployment_arguments_required: { retryable: false, recoveryAction: "Inside a build session a deploy needs artifactVersionId, idempotencyKey, and the inspectedSourceHash and expectedBundleSha256 that platform_inspect_artifact_app returned. The fields named after the code are missing; add them and call again." },
|
|
2577
2648
|
artifact_source_conflict: { retryable: false, recoveryAction: "inspectedSourceHash no longer matches the session's source fence. Use currentSourceHash from this error when present, or read the session for its current sourceHash (or check out again into a new directory). Keep your local edits, inspect again, then deploy with the fresh hash." },
|
|
2578
2649
|
artifact_operation_pending: { retryable: true, recoveryAction: "Another operation on this app has not settled. Read it with platform_deploy_operation, using pendingOperationId from this error when present (a deploy that already landed settles on that read), or platform_read_build_session, then call this tool again once it is terminal." },
|
|
@@ -2584,7 +2655,9 @@ export function structuredToolError(message) {
|
|
|
2584
2655
|
const code = recoveryErrorCode(message);
|
|
2585
2656
|
// A 4xx means the same request will be refused again; only 5xx, timeouts and rate limits are worth retrying unchanged.
|
|
2586
2657
|
const retryable = /^platform_harness_http_error:5|timeout|rate_limited|unavailable|internal_error/.test(message);
|
|
2587
|
-
|
|
2658
|
+
// A failure code after the error code can have its own guidance (artifact_deploy_failed:build_session_cancelled).
|
|
2659
|
+
const detailCode = /^[a-z_]+:([a-z][a-z0-9_]{2,80})\b/.exec(message)?.[1];
|
|
2660
|
+
const selected = (detailCode ? BUILD_MCP_RECOVERY_ERRORS[`${code}:${detailCode}`] : undefined) ?? BUILD_MCP_RECOVERY_ERRORS[code] ?? { retryable, recoveryAction: !retryable && /^platform_harness_http_error:4|^platform_mcp_tool_error:/.test(message)
|
|
2588
2661
|
? "Topline refused this request as sent. Read the code, correct the input or state it names, then call the tool again; the same input fails the same way."
|
|
2589
2662
|
: "Inspect the code and message, correct the input if needed, then retry the same tool." };
|
|
2590
2663
|
const structuredContent = { ok: false, error: { code, message, ...selected, ...conflictFieldsFromMessage(message) } };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"package": {
|
|
4
4
|
"name": "@topline-build/harness-mcp",
|
|
5
|
-
"version": "0.9.
|
|
5
|
+
"version": "0.9.17",
|
|
6
6
|
"bin": {
|
|
7
7
|
"topline-mcp": "dist/cli.js"
|
|
8
8
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"defaultVersion": "2025-11-25",
|
|
13
13
|
"server": {
|
|
14
14
|
"name": "topline-build-stdio",
|
|
15
|
-
"version": "0.9.
|
|
15
|
+
"version": "0.9.17"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"generatedFrom": {
|
|
@@ -482,7 +482,7 @@
|
|
|
482
482
|
{
|
|
483
483
|
"code": "artifact_app_scaffold_starter_invalid",
|
|
484
484
|
"retryable": false,
|
|
485
|
-
"recoveryAction": "Use one of the starters: bounded-bedrock-assistant, cache-warmed-multi-source-dashboard, internal-action-tool, live-operations-dashboard, materialized-sql-data-product, precomputed-s3-report, private-api-first-app, viewer-scoped-customer-portal."
|
|
485
|
+
"recoveryAction": "Use one of the starters: bounded-bedrock-assistant, cache-warmed-multi-source-dashboard, internal-action-tool, live-operations-dashboard, materialized-sql-data-product, precomputed-s3-report, private-api-first-app, table-approvals-app, viewer-scoped-customer-portal."
|
|
486
486
|
},
|
|
487
487
|
{
|
|
488
488
|
"code": "artifact_app_scaffold_starter_shape_conflict",
|
|
@@ -494,6 +494,21 @@
|
|
|
494
494
|
"retryable": false,
|
|
495
495
|
"recoveryAction": "The session moved to a newer version. Read the session (platform_read_build_session). A build session always starts from the app's current version; Build MCP can't check out an older saved version, so to go back, deploy source you saved before (or ask the coding agent in Topline to go back to version N). For a refused deploy: keep your local edits, run platform_inspect_artifact_app again, then deploy with the current artifactVersionId and the new inspectedSourceHash. For a refused validation request: don't deploy again. Wait for the current version's deploy to settle (platform_deploy_operation), run its checks and smoke, prepare it with platform_prepare_artifact_validation, then call platform_request_artifact_validation with that prepared evidence."
|
|
496
496
|
},
|
|
497
|
+
{
|
|
498
|
+
"code": "artifact_package_not_ready",
|
|
499
|
+
"retryable": false,
|
|
500
|
+
"recoveryAction": "platform_inspect_artifact_app reports problems Topline's build would fail on (named after the code, with file and line), so nothing was uploaded or spent. Fix them, run platform_inspect_artifact_app until packageReady is true, then deploy with the new expectedBundleSha256."
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
"code": "build_session_project_id_not_allowed",
|
|
504
|
+
"retryable": false,
|
|
505
|
+
"recoveryAction": "Inside a build session the draft already belongs to the session's artifact and project. Leave projectId out and call again."
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
"code": "artifact_deploy_failed:build_session_cancelled",
|
|
509
|
+
"retryable": false,
|
|
510
|
+
"recoveryAction": "This deploy was cancelled because its build session was closed before it finished; the source wasn't at fault. Start a new build session for this artifact, then inspect and deploy again."
|
|
511
|
+
},
|
|
497
512
|
{
|
|
498
513
|
"code": "build_session_deployment_arguments_required",
|
|
499
514
|
"retryable": false,
|
|
@@ -780,6 +795,7 @@
|
|
|
780
795
|
"materialized-sql-data-product",
|
|
781
796
|
"precomputed-s3-report",
|
|
782
797
|
"private-api-first-app",
|
|
798
|
+
"table-approvals-app",
|
|
783
799
|
"viewer-scoped-customer-portal"
|
|
784
800
|
],
|
|
785
801
|
"description": "Optional Build cookbook example to start from (single shape only). Scaffolds the recipe's page and private routes with placeholder answers and scaffold-labelled checks, and returns the recipe to follow. Datasets, source bindings and secrets are left for you to add from your own data."
|
|
@@ -929,7 +945,7 @@
|
|
|
929
945
|
},
|
|
930
946
|
{
|
|
931
947
|
"name": "platform_deploy_artifact_app",
|
|
932
|
-
"description": "Package a local artifact app directory, upload it, deploy a private draft, and return status.",
|
|
948
|
+
"description": "Package a local artifact app directory, upload it, deploy a private draft, and return status. It runs platform_inspect_artifact_app's manifest and JavaScript syntax checks first and refuses with artifact_package_not_ready, before uploading or spending budget, while any of those problems remain. Inside a build session, leave projectId out.",
|
|
933
949
|
"annotations": {
|
|
934
950
|
"title": "Platform Deploy Artifact App",
|
|
935
951
|
"readOnlyHint": false,
|
|
@@ -1021,7 +1037,15 @@
|
|
|
1021
1037
|
"type": [
|
|
1022
1038
|
"string",
|
|
1023
1039
|
"null"
|
|
1024
|
-
]
|
|
1040
|
+
],
|
|
1041
|
+
"description": "The one deploy id: pass it to platform_wait_artifact_deploy and platform_deploy_operation."
|
|
1042
|
+
},
|
|
1043
|
+
"deployTaskId": {
|
|
1044
|
+
"type": [
|
|
1045
|
+
"string",
|
|
1046
|
+
"null"
|
|
1047
|
+
],
|
|
1048
|
+
"description": "The worker task that ran the deploy, for logs only. Not an operation id."
|
|
1025
1049
|
},
|
|
1026
1050
|
"bundle": {
|
|
1027
1051
|
"type": "object"
|
|
@@ -1115,7 +1139,7 @@
|
|
|
1115
1139
|
},
|
|
1116
1140
|
{
|
|
1117
1141
|
"name": "platform_inspect_artifact_app",
|
|
1118
|
-
"description": "Inspect local artifact paths and package boundaries without
|
|
1142
|
+
"description": "Inspect local artifact paths and package boundaries without creating a remote draft, building or spending anything. Runs the manifest and data-binding checks Topline's build would fail (datasets[].name and route, routes[].path, ./_artifact/data/<name> references with no matching dataset) and a node --check of each .js/.mjs/.cjs file (javascript_syntax_error with file and line). When this computer is signed in to Topline, it also sends the bundle to Topline's preflight, which runs the build's own local validation (undeclared_package_import and the rest) and the manifest rules the server applies on save; serverChecks says whether that ran. packageReady is false and problems lists each one until they are fixed. warnings lists static text the build's page-text rules would refuse if the page shows it.",
|
|
1119
1143
|
"annotations": {
|
|
1120
1144
|
"title": "Platform Inspect Artifact App",
|
|
1121
1145
|
"readOnlyHint": true,
|
|
@@ -1167,7 +1191,12 @@
|
|
|
1167
1191
|
"description": "Static text that matches a rule Topline's render smoke applies to the page (rendered_text_rule:sample_or_mock_data_text), with the file and phrase. The build fails only if the rendered page shows it."
|
|
1168
1192
|
},
|
|
1169
1193
|
"serverManifestValidationRequired": {
|
|
1170
|
-
"type": "boolean"
|
|
1194
|
+
"type": "boolean",
|
|
1195
|
+
"description": "True when Topline's preflight did not run (see serverChecks), so the server's manifest rules and the build's local validation are still unchecked."
|
|
1196
|
+
},
|
|
1197
|
+
"serverChecks": {
|
|
1198
|
+
"type": "string",
|
|
1199
|
+
"description": "passed, failed (its problems are in problems), or skipped:<reason> (not signed in, an older Topline without the preflight, or the request failed)."
|
|
1171
1200
|
},
|
|
1172
1201
|
"appDir": {
|
|
1173
1202
|
"type": "string"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Generated from `src/index.ts#BUILD_MCP_TOOLS`. Do not edit this file by hand.
|
|
4
4
|
|
|
5
|
-
Package: `@topline-build/harness-mcp@0.9.
|
|
5
|
+
Package: `@topline-build/harness-mcp@0.9.17`
|
|
6
6
|
Transport: `stdio`
|
|
7
7
|
Default protocol: `2025-11-25`
|
|
8
8
|
Canonical guide: https://topline.build/docs/build-mcp-guide
|
|
@@ -91,9 +91,12 @@ Tool failures set `isError: true` and return `structuredContent.error` with `cod
|
|
|
91
91
|
- `artifact_app_manifest_too_large` (not automatically retryable): Keep artifact-app.json below 512 KiB. Move application data and source into separate files, then inspect again.
|
|
92
92
|
- `artifact_app_scaffold_target_not_empty` (not automatically retryable): Choose an empty appDir or deploy the existing app without scaffolding.
|
|
93
93
|
- `artifact_app_scaffold_shape_invalid` (not automatically retryable): Use shape single or web-and-api.
|
|
94
|
-
- `artifact_app_scaffold_starter_invalid` (not automatically retryable): Use one of the starters: bounded-bedrock-assistant, cache-warmed-multi-source-dashboard, internal-action-tool, live-operations-dashboard, materialized-sql-data-product, precomputed-s3-report, private-api-first-app, viewer-scoped-customer-portal.
|
|
94
|
+
- `artifact_app_scaffold_starter_invalid` (not automatically retryable): Use one of the starters: bounded-bedrock-assistant, cache-warmed-multi-source-dashboard, internal-action-tool, live-operations-dashboard, materialized-sql-data-product, precomputed-s3-report, private-api-first-app, table-approvals-app, viewer-scoped-customer-portal.
|
|
95
95
|
- `artifact_app_scaffold_starter_shape_conflict` (not automatically retryable): A starter scaffolds the single shape; leave shape out or set it to single.
|
|
96
96
|
- `artifact_version_conflict` (not automatically retryable): The session moved to a newer version. Read the session (platform_read_build_session). A build session always starts from the app's current version; Build MCP can't check out an older saved version, so to go back, deploy source you saved before (or ask the coding agent in Topline to go back to version N). For a refused deploy: keep your local edits, run platform_inspect_artifact_app again, then deploy with the current artifactVersionId and the new inspectedSourceHash. For a refused validation request: don't deploy again. Wait for the current version's deploy to settle (platform_deploy_operation), run its checks and smoke, prepare it with platform_prepare_artifact_validation, then call platform_request_artifact_validation with that prepared evidence.
|
|
97
|
+
- `artifact_package_not_ready` (not automatically retryable): platform_inspect_artifact_app reports problems Topline's build would fail on (named after the code, with file and line), so nothing was uploaded or spent. Fix them, run platform_inspect_artifact_app until packageReady is true, then deploy with the new expectedBundleSha256.
|
|
98
|
+
- `build_session_project_id_not_allowed` (not automatically retryable): Inside a build session the draft already belongs to the session's artifact and project. Leave projectId out and call again.
|
|
99
|
+
- `artifact_deploy_failed:build_session_cancelled` (not automatically retryable): This deploy was cancelled because its build session was closed before it finished; the source wasn't at fault. Start a new build session for this artifact, then inspect and deploy again.
|
|
97
100
|
- `build_session_deployment_arguments_required` (not automatically retryable): Inside a build session a deploy needs artifactVersionId, idempotencyKey, and the inspectedSourceHash and expectedBundleSha256 that platform_inspect_artifact_app returned. The fields named after the code are missing; add them and call again.
|
|
98
101
|
- `artifact_source_conflict` (not automatically retryable): inspectedSourceHash no longer matches the session's source fence. Use currentSourceHash from this error when present, or read the session for its current sourceHash (or check out again into a new directory). Keep your local edits, inspect again, then deploy with the fresh hash.
|
|
99
102
|
- `artifact_operation_pending` (retryable): Another operation on this app has not settled. Read it with platform_deploy_operation, using pendingOperationId from this error when present (a deploy that already landed settles on that read), or platform_read_build_session, then call this tool again once it is terminal.
|
|
@@ -404,6 +407,7 @@ Input schema:
|
|
|
404
407
|
"materialized-sql-data-product",
|
|
405
408
|
"precomputed-s3-report",
|
|
406
409
|
"private-api-first-app",
|
|
410
|
+
"table-approvals-app",
|
|
407
411
|
"viewer-scoped-customer-portal"
|
|
408
412
|
],
|
|
409
413
|
"description": "Optional Build cookbook example to start from (single shape only). Scaffolds the recipe's page and private routes with placeholder answers and scaffold-labelled checks, and returns the recipe to follow. Datasets, source bindings and secrets are left for you to add from your own data."
|
|
@@ -544,7 +548,7 @@ Output schema:
|
|
|
544
548
|
|
|
545
549
|
### `platform_deploy_artifact_app`
|
|
546
550
|
|
|
547
|
-
Package a local artifact app directory, upload it, deploy a private draft, and return status.
|
|
551
|
+
Package a local artifact app directory, upload it, deploy a private draft, and return status. It runs platform_inspect_artifact_app's manifest and JavaScript syntax checks first and refuses with artifact_package_not_ready, before uploading or spending budget, while any of those problems remain. Inside a build session, leave projectId out.
|
|
548
552
|
|
|
549
553
|
Safety: read-only=false, destructive=false, idempotent=false, open-world=true.
|
|
550
554
|
|
|
@@ -664,7 +668,15 @@ Output schema:
|
|
|
664
668
|
"type": [
|
|
665
669
|
"string",
|
|
666
670
|
"null"
|
|
667
|
-
]
|
|
671
|
+
],
|
|
672
|
+
"description": "The one deploy id: pass it to platform_wait_artifact_deploy and platform_deploy_operation."
|
|
673
|
+
},
|
|
674
|
+
"deployTaskId": {
|
|
675
|
+
"type": [
|
|
676
|
+
"string",
|
|
677
|
+
"null"
|
|
678
|
+
],
|
|
679
|
+
"description": "The worker task that ran the deploy, for logs only. Not an operation id."
|
|
668
680
|
},
|
|
669
681
|
"bundle": {
|
|
670
682
|
"type": "object"
|
|
@@ -742,7 +754,7 @@ Output schema:
|
|
|
742
754
|
|
|
743
755
|
### `platform_inspect_artifact_app`
|
|
744
756
|
|
|
745
|
-
Inspect local artifact paths and package boundaries without
|
|
757
|
+
Inspect local artifact paths and package boundaries without creating a remote draft, building or spending anything. Runs the manifest and data-binding checks Topline's build would fail (datasets[].name and route, routes[].path, ./_artifact/data/<name> references with no matching dataset) and a node --check of each .js/.mjs/.cjs file (javascript_syntax_error with file and line). When this computer is signed in to Topline, it also sends the bundle to Topline's preflight, which runs the build's own local validation (undeclared_package_import and the rest) and the manifest rules the server applies on save; serverChecks says whether that ran. packageReady is false and problems lists each one until they are fixed. warnings lists static text the build's page-text rules would refuse if the page shows it.
|
|
746
758
|
|
|
747
759
|
Safety: read-only=true, destructive=false, idempotent=false, open-world=false.
|
|
748
760
|
|
|
@@ -822,7 +834,12 @@ Output schema:
|
|
|
822
834
|
"description": "Static text that matches a rule Topline's render smoke applies to the page (rendered_text_rule:sample_or_mock_data_text), with the file and phrase. The build fails only if the rendered page shows it."
|
|
823
835
|
},
|
|
824
836
|
"serverManifestValidationRequired": {
|
|
825
|
-
"type": "boolean"
|
|
837
|
+
"type": "boolean",
|
|
838
|
+
"description": "True when Topline's preflight did not run (see serverChecks), so the server's manifest rules and the build's local validation are still unchecked."
|
|
839
|
+
},
|
|
840
|
+
"serverChecks": {
|
|
841
|
+
"type": "string",
|
|
842
|
+
"description": "passed, failed (its problems are in problems), or skipped:<reason> (not signed in, an older Topline without the preflight, or the request failed)."
|
|
826
843
|
},
|
|
827
844
|
"appDir": {
|
|
828
845
|
"type": "string"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topline-build/harness-mcp",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.17",
|
|
4
4
|
"description": "Topline Build MCP for creating and deploying artifact app drafts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist/",
|
|
18
18
|
"docs/generated/",
|
|
19
|
+
"templates/",
|
|
19
20
|
"CHANGELOG.md",
|
|
20
21
|
"README.md",
|
|
21
22
|
"scripts/certify-live.mjs"
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
// Starter from the Build cookbook recipe "table-approvals-app": people submit
|
|
5
|
+
// requests, see their own, and approvers decide them. Every read and write runs
|
|
6
|
+
// in this server code through server table SQL (manifest `serverTables: true`);
|
|
7
|
+
// the manifest declares no `tables[]`, so the browser can't list rows itself.
|
|
8
|
+
// Create the two tables first (the recipe has the SQL), then rename them here.
|
|
9
|
+
const TITLE = "__ARTIFACT_TITLE__";
|
|
10
|
+
const REQUESTS = "company_data.approval_requests";
|
|
11
|
+
const APPROVERS = "company_data.approval_approvers";
|
|
12
|
+
const STATUSES = ["approved", "rejected"];
|
|
13
|
+
|
|
14
|
+
/** POST one statement to the platform's server table SQL endpoint. Server code only. */
|
|
15
|
+
export async function tablesSql(req, sql, params = {}, actingUser) {
|
|
16
|
+
const url = header(req, "x-platform-tables-sql-url");
|
|
17
|
+
const token = header(req, "x-platform-tables-token");
|
|
18
|
+
if (!url || !token) throw Object.assign(new Error("server_tables_unavailable"), { status: 503 });
|
|
19
|
+
const response = await fetch(url, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
22
|
+
body: JSON.stringify({ sql, params, ...(actingUser ? { actingUser } : {}) })
|
|
23
|
+
});
|
|
24
|
+
const body = await response.json().catch(() => ({}));
|
|
25
|
+
if (!response.ok || body.ok === false) {
|
|
26
|
+
const code = `${body.error ?? `table_sql_http_${response.status}`}${body.sqlstate ? `:${body.sqlstate}` : ""}`;
|
|
27
|
+
throw Object.assign(new Error(code), { status: response.status, hint: body.hint });
|
|
28
|
+
}
|
|
29
|
+
// Every value comes back as a string; convert what you need.
|
|
30
|
+
return { rows: body.rows ?? [], rowCount: Number(body.rowCount ?? 0) };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function header(req, name) {
|
|
34
|
+
const value = req.headers?.[name];
|
|
35
|
+
return Array.isArray(value) ? value[0] : value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const LIST_COLUMNS = `_row_id as id, _version as version, requester_email, title, details, status, decided_by, decision_note,
|
|
39
|
+
to_char(_created_at at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as created_at`;
|
|
40
|
+
|
|
41
|
+
/** The app's rules, over an injected `sql(statement, params)` so --test can run them without a table. */
|
|
42
|
+
export function approvalsService(sql, viewer) {
|
|
43
|
+
const email = String(viewer ?? "").trim().toLowerCase();
|
|
44
|
+
async function isApprover() {
|
|
45
|
+
const { rows } = await sql(`select 1 as ok from ${APPROVERS} where lower(email) = :email and active and _deleted_at is null limit 1`, { email });
|
|
46
|
+
return rows.length > 0;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
async overview() {
|
|
50
|
+
const approver = await isApprover();
|
|
51
|
+
const mine = await sql(`select ${LIST_COLUMNS} from ${REQUESTS} where lower(requester_email) = :email and _deleted_at is null order by _created_at desc limit 200`, { email });
|
|
52
|
+
const queue = approver
|
|
53
|
+
? await sql(`select ${LIST_COLUMNS} from ${REQUESTS} where status = 'pending' and _deleted_at is null order by _created_at limit 200`, {})
|
|
54
|
+
: { rows: [] };
|
|
55
|
+
return { status: 200, body: { ready: true, viewer: email, approver, mine: mine.rows, queue: queue.rows } };
|
|
56
|
+
},
|
|
57
|
+
async submit(input) {
|
|
58
|
+
const title = typeof input?.title === "string" ? input.title.trim() : "";
|
|
59
|
+
const details = typeof input?.details === "string" ? input.details.trim() : "";
|
|
60
|
+
if (!title || title.length > 200 || details.length > 4000) return { status: 400, body: { error: "invalid_request", fields: ["title (1-200 characters)", "details (up to 4000)"] } };
|
|
61
|
+
await sql(`insert into ${REQUESTS} (requester_email, title, details, status) values (:email, :title, :details, 'pending')`, { email, title, details });
|
|
62
|
+
return { status: 201, body: { ok: true } };
|
|
63
|
+
},
|
|
64
|
+
async decide(input) {
|
|
65
|
+
const id = typeof input?.id === "string" ? input.id : "";
|
|
66
|
+
const version = Number(input?.version);
|
|
67
|
+
const status = input?.decision;
|
|
68
|
+
const note = typeof input?.note === "string" ? input.note.trim().slice(0, 2000) : "";
|
|
69
|
+
if (!/^[0-9a-f-]{36}$/i.test(id) || !Number.isInteger(version) || !STATUSES.includes(status)) return { status: 400, body: { error: "invalid_decision" } };
|
|
70
|
+
if (status === "rejected" && !note) return { status: 400, body: { error: "note_required" } };
|
|
71
|
+
if (!(await isApprover())) return { status: 403, body: { error: "approver_required" } };
|
|
72
|
+
const { rowCount } = await sql(
|
|
73
|
+
`update ${REQUESTS} set status = :status, decided_by = :email, decided_at = CAST(:now AS timestamptz), decision_note = :note
|
|
74
|
+
where _row_id = :id and _version = :version and status = 'pending' and lower(requester_email) <> :email and _deleted_at is null`,
|
|
75
|
+
{ status, email, now: new Date().toISOString(), note, id, version }
|
|
76
|
+
);
|
|
77
|
+
if (rowCount > 0) return { status: 200, body: { ok: true } };
|
|
78
|
+
const { rows } = await sql(`select ${LIST_COLUMNS} from ${REQUESTS} where _row_id = :id`, { id });
|
|
79
|
+
const row = rows[0];
|
|
80
|
+
if (!row) return { status: 404, body: { error: "request_not_found" } };
|
|
81
|
+
if (String(row.requester_email).toLowerCase() === email) return { status: 403, body: { error: "cannot_decide_own_request" } };
|
|
82
|
+
return { status: 409, body: { error: "request_changed", row } };
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function readJson(req) {
|
|
88
|
+
if (req.body !== undefined) return typeof req.body === "string" ? JSON.parse(req.body || "{}") : req.body;
|
|
89
|
+
const chunks = [];
|
|
90
|
+
for await (const chunk of req) chunks.push(Buffer.from(chunk));
|
|
91
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
92
|
+
return text ? JSON.parse(text) : {};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function send(res, status, body) {
|
|
96
|
+
res.statusCode = status;
|
|
97
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
98
|
+
res.setHeader("cache-control", "no-store");
|
|
99
|
+
res.end(JSON.stringify(body));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function artifactApp(req, res) {
|
|
103
|
+
const url = new URL(req.url ?? "/", "http://artifact.local");
|
|
104
|
+
const method = req.method ?? "GET";
|
|
105
|
+
const api = ["/_artifact/api/requests", "/_artifact/api/decisions"].find((route) => url.pathname.endsWith(route));
|
|
106
|
+
if (!api) {
|
|
107
|
+
res.setHeader("content-type", "text/html; charset=utf-8");
|
|
108
|
+
res.end(page);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const viewer = header(req, "x-platform-viewer-email");
|
|
112
|
+
if (!viewer) return send(res, 401, { error: "viewer_required" });
|
|
113
|
+
const service = approvalsService((statement, params) => tablesSql(req, statement, params, viewer), viewer);
|
|
114
|
+
try {
|
|
115
|
+
let result;
|
|
116
|
+
if (api === "/_artifact/api/requests" && method === "GET") result = await service.overview();
|
|
117
|
+
else if (api === "/_artifact/api/requests" && method === "POST") result = await service.submit(await readJson(req));
|
|
118
|
+
else if (api === "/_artifact/api/decisions" && method === "POST") result = await service.decide(await readJson(req));
|
|
119
|
+
else return send(res, 405, { error: "method_not_allowed" });
|
|
120
|
+
send(res, result.status, result.body);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const code = error instanceof Error ? error.message : "request_failed";
|
|
123
|
+
// Before the tables exist (or on a sandbox preview) answer 200 with a setup state,
|
|
124
|
+
// so the page and the smoke check stay healthy and say what is missing.
|
|
125
|
+
const notSetUp = ["server_tables_unavailable", "server_tables_not_declared", "company_table_not_found", "company_table_sql_failed:42P01"];
|
|
126
|
+
if (method === "GET" && notSetUp.some((prefix) => code.startsWith(prefix))) {
|
|
127
|
+
return send(res, 200, { ready: false, reason: code });
|
|
128
|
+
}
|
|
129
|
+
if (code.startsWith("preview_writes_not_allowed")) return send(res, 403, { error: "draft_is_read_only" });
|
|
130
|
+
console.error(`[approvals] ${code}`);
|
|
131
|
+
send(res, error?.status && error.status < 500 ? 400 : 502, { error: "request_failed", code });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const escapeHtml = (value) => String(value).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
136
|
+
|
|
137
|
+
const page = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
138
|
+
<title>${escapeHtml(TITLE)}</title>
|
|
139
|
+
<style>
|
|
140
|
+
body{font:15px/1.5 system-ui,sans-serif;margin:0;color:#1d1d1b;background:#fafaf7}main{max-width:880px;margin:0 auto;padding:24px 16px}
|
|
141
|
+
h1{font-size:24px;margin:0 0 4px}h2{font-size:17px;margin:28px 0 8px}form,li{background:#fff;border:1px solid #dcdcd4;border-radius:8px;padding:12px}
|
|
142
|
+
label{display:block;font-weight:600;margin-top:8px}input,textarea{width:100%;box-sizing:border-box;font:inherit;padding:6px;margin-top:4px}
|
|
143
|
+
button{font:inherit;margin-top:10px;padding:6px 12px;cursor:pointer}ul{list-style:none;padding:0;display:grid;gap:8px}
|
|
144
|
+
.meta{color:#5d5d55;font-size:13px}.status{font-weight:600;text-transform:capitalize}[role=alert]{color:#a22}
|
|
145
|
+
</style></head><body><main data-platform-artifact-root>
|
|
146
|
+
<h1>${escapeHtml(TITLE)}</h1><p class="meta" id="state">Loading requests...</p>
|
|
147
|
+
<section aria-labelledby="new-h"><h2 id="new-h">New request</h2>
|
|
148
|
+
<form id="new"><label for="title">Title</label><input id="title" name="title" maxlength="200" required>
|
|
149
|
+
<label for="details">Details</label><textarea id="details" name="details" rows="3" maxlength="4000"></textarea>
|
|
150
|
+
<button type="submit">Submit request</button><p id="new-msg" role="status"></p></form></section>
|
|
151
|
+
<section aria-labelledby="mine-h"><h2 id="mine-h">My requests</h2><ul id="mine"></ul></section>
|
|
152
|
+
<section aria-labelledby="queue-h" id="queue-section" hidden><h2 id="queue-h">Waiting for your decision</h2><ul id="queue"></ul></section>
|
|
153
|
+
</main><script type="module">
|
|
154
|
+
const api = (p) => new URL("_artifact/api/" + p, document.baseURI);
|
|
155
|
+
const esc = (v) => String(v ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
156
|
+
const state = document.getElementById("state");
|
|
157
|
+
function item(r, decide) {
|
|
158
|
+
const note = r.decision_note ? '<div class="meta">Note: ' + esc(r.decision_note) + '</div>' : "";
|
|
159
|
+
const who = decide ? esc(r.requester_email) + " - " : "";
|
|
160
|
+
const actions = decide ? '<label>Note (required to reject)<input data-note></label><button data-d="approved">Approve</button> <button data-d="rejected">Reject</button><p role="alert"></p>' : "";
|
|
161
|
+
return '<li data-id="' + esc(r.id) + '" data-version="' + esc(r.version) + '"><strong>' + esc(r.title) + '</strong> <span class="status">' + esc(r.status) + '</span>'
|
|
162
|
+
+ '<div class="meta">' + who + esc(r.created_at) + (r.decided_by ? " - decided by " + esc(r.decided_by) : "") + '</div>'
|
|
163
|
+
+ (r.details ? '<div>' + esc(r.details) + '</div>' : "") + note + actions + '</li>';
|
|
164
|
+
}
|
|
165
|
+
async function load() {
|
|
166
|
+
const res = await fetch(api("requests"), { cache: "no-store" });
|
|
167
|
+
const data = await res.json().catch(() => ({}));
|
|
168
|
+
if (!res.ok) { state.textContent = "Requests could not load (" + (data.code || data.error || res.status) + ")."; return; }
|
|
169
|
+
if (!data.ready) { state.textContent = "Not set up yet: the request tables don't exist or server table access is off (" + esc(data.reason) + ")."; return; }
|
|
170
|
+
state.textContent = data.approver ? "You can submit requests and decide others' requests." : "You can submit requests and follow their status.";
|
|
171
|
+
document.getElementById("mine").innerHTML = data.mine.length ? data.mine.map((r) => item(r, false)).join("") : "<li>No requests yet.</li>";
|
|
172
|
+
document.getElementById("queue-section").hidden = !data.approver;
|
|
173
|
+
document.getElementById("queue").innerHTML = data.queue.length ? data.queue.map((r) => item(r, true)).join("") : "<li>Nothing is waiting.</li>";
|
|
174
|
+
}
|
|
175
|
+
document.getElementById("new").addEventListener("submit", async (e) => {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
const msg = document.getElementById("new-msg");
|
|
178
|
+
const res = await fetch(api("requests"), { method: "POST", headers: { "content-type": "application/json" },
|
|
179
|
+
body: JSON.stringify({ title: e.target.title.value, details: e.target.details.value }) });
|
|
180
|
+
const data = await res.json().catch(() => ({}));
|
|
181
|
+
msg.textContent = res.ok ? "Submitted." : "Not submitted (" + (data.code || data.error || res.status) + ").";
|
|
182
|
+
if (res.ok) { e.target.reset(); load(); }
|
|
183
|
+
});
|
|
184
|
+
document.getElementById("queue").addEventListener("click", async (e) => {
|
|
185
|
+
const button = e.target.closest("button[data-d]"); if (!button) return;
|
|
186
|
+
const li = button.closest("li");
|
|
187
|
+
const res = await fetch(api("decisions"), { method: "POST", headers: { "content-type": "application/json" },
|
|
188
|
+
body: JSON.stringify({ id: li.dataset.id, version: Number(li.dataset.version), decision: button.dataset.d, note: li.querySelector("[data-note]").value }) });
|
|
189
|
+
const data = await res.json().catch(() => ({}));
|
|
190
|
+
if (res.ok) return load();
|
|
191
|
+
li.querySelector("[role=alert]").textContent = res.status === 409 ? "Someone changed this request first; reloading." : "Not saved (" + (data.code || data.error) + ").";
|
|
192
|
+
if (res.status === 409) setTimeout(load, 1200);
|
|
193
|
+
});
|
|
194
|
+
load();
|
|
195
|
+
</script></body></html>`;
|
|
196
|
+
|
|
197
|
+
async function scaffoldChecks() {
|
|
198
|
+
// A fake table, so the app's rules run without a deployment. Not proof of the deployed app.
|
|
199
|
+
const rows = [{ id: "00000000-0000-4000-8000-000000000001", version: "1", requester_email: "sam@example.com", status: "pending" }];
|
|
200
|
+
const approvers = new Set(["ana@example.com"]);
|
|
201
|
+
const fake = async (statement, params) => {
|
|
202
|
+
if (statement.includes(APPROVERS)) return { rows: approvers.has(params.email) ? [{ ok: "1" }] : [], rowCount: 0 };
|
|
203
|
+
if (statement.startsWith("insert")) { rows.push({ id: "new", version: "1", requester_email: params.email, status: "pending" }); return { rows: [], rowCount: 1 }; }
|
|
204
|
+
if (statement.startsWith("update")) {
|
|
205
|
+
const row = rows.find((r) => r.id === params.id && Number(r.version) === params.version && r.status === "pending" && r.requester_email !== params.email);
|
|
206
|
+
if (row) { row.status = params.status; row.version = String(params.version + 1); }
|
|
207
|
+
return { rows: [], rowCount: row ? 1 : 0 };
|
|
208
|
+
}
|
|
209
|
+
if (statement.includes("where _row_id = :id")) return { rows: rows.filter((r) => r.id === params.id), rowCount: 0 };
|
|
210
|
+
return { rows: rows.filter((r) => r.status === "pending"), rowCount: 0 };
|
|
211
|
+
};
|
|
212
|
+
const sam = approvalsService(fake, "sam@example.com");
|
|
213
|
+
const ana = approvalsService(fake, "ana@example.com");
|
|
214
|
+
const results = [
|
|
215
|
+
["a request without a title is refused", (await sam.submit({ title: " " })).status === 400],
|
|
216
|
+
["a person submits a request", (await sam.submit({ title: "Day off", details: "Friday" })).status === 201],
|
|
217
|
+
["a non-approver cannot decide", (await sam.decide({ id: rows[0].id, version: 1, decision: "approved" })).status === 403],
|
|
218
|
+
["rejecting needs a note", (await ana.decide({ id: rows[0].id, version: 1, decision: "rejected" })).status === 400],
|
|
219
|
+
["an approver approves the version they saw", (await ana.decide({ id: rows[0].id, version: 1, decision: "approved" })).status === 200],
|
|
220
|
+
["a stale decision gets 409", (await ana.decide({ id: rows[0].id, version: 1, decision: "approved" })).status === 409]
|
|
221
|
+
];
|
|
222
|
+
return [
|
|
223
|
+
{ description: "Scaffold check: the page renders a visible app root.", required: true, status: page.includes("data-platform-artifact-root") ? "passed" : "failed", summary: "Generated starter check; not proof of implemented behavior.", evidence: { selector: "data-platform-artifact-root", scaffold: true } },
|
|
224
|
+
...results.map(([name, ok]) => ({ description: `Scaffold check: ${name} (fake table).`, required: false, status: ok ? "passed" : "failed", summary: "Starter rule check against an in-memory table; replace with checks of your real rules.", evidence: { scaffold: true } }))
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (process.argv.includes("--build")) {
|
|
229
|
+
mkdirSync("dist", { recursive: true });
|
|
230
|
+
writeFileSync(path.join("dist", "index.html"), page, "utf8");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (process.argv.includes("--test")) {
|
|
234
|
+
const tests = await scaffoldChecks();
|
|
235
|
+
if (process.argv.includes("--artifact-tests-json")) console.log(JSON.stringify({ tests }));
|
|
236
|
+
else {
|
|
237
|
+
const failed = tests.filter((test) => test.status !== "passed");
|
|
238
|
+
for (const test of failed) console.error(`failed: ${test.description}`);
|
|
239
|
+
if (failed.length) process.exitCode = 1;
|
|
240
|
+
else console.log("artifact app starter ok");
|
|
241
|
+
}
|
|
242
|
+
} else if (process.argv.includes("--build")) {
|
|
243
|
+
console.log("artifact app starter ok");
|
|
244
|
+
}
|