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
6 changes: 5 additions & 1 deletion packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
defaultWorkflowManifest,
parseManifestFileOption,
parseLogFileOption,
typesHandler,
} from "../lib";
import { createLogger } from "./utils/createLogger";

Expand Down Expand Up @@ -143,7 +144,10 @@ const _run = async (options: WorkflowCommandOptions) => {
fs.writeFileSync(outputFile, yaml.stringify(printableOutput, null, 2));
break;
case "json":
fs.writeFileSync(outputFile, JSON.stringify(printableOutput, null, 2));
fs.writeFileSync(
outputFile,
JSON.stringify(printableOutput, typesHandler, 2)
);
break;
default:
throw new Error(
Expand Down
22 changes: 17 additions & 5 deletions packages/cli/src/lib/helpers/workflow-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export function cueExists(logger: Logger): boolean {
return stdout ? stdout.startsWith("cue version ") : false;
}

export const typesHandler = (_: unknown, value: unknown): unknown => {
if (value instanceof Map) {
return Array.from(value).reduce(
(obj: Record<string, unknown>, [key, value]) => {
obj[key] = value;
return obj;
},
{}
);
}

return value;
};

export function validateOutput(
output: WorkflowOutput,
validateScriptPath: string,
Expand All @@ -34,13 +48,11 @@ export function validateOutput(

fs.writeFileSync(
jsonOutput,
JSON.stringify({ data, error: error?.message }, null, 2)
JSON.stringify({ data, error: error?.message }, typesHandler, 2)
);

const { stderr } = runCommandSync(
`cue vet -d ${selector} ${validateScriptPath} ${jsonOutput}`,
logger
);
const args = [selector, validateScriptPath, jsonOutput];

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input

This array element which depends on [library input](1) is later used in a [shell command](2).

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input

This array element which depends on [library input](1) is later used in a [shell command](2).

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input

This array element which depends on [library input](1) is later used in a [shell command](2).
const { stderr } = runCommandSync(`cue vet -d ${args.join(" ")}`, logger);

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input

This string concatenation which depends on [library input](1) is later used in a [shell command](2). This string concatenation which depends on [library input](3) is later used in a [shell command](2).

if (fs.existsSync(jsonOutput)) {
fs.unlinkSync(jsonOutput);
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/workflow/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { intlMsg } from "../intl";
import { WorkflowOutput } from "./types";
import { typesHandler } from "../helpers";

import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -44,7 +45,7 @@ export function printJobOutput(output: WorkflowOutput): void {
console.log(`Job status: ${output.status}`);

if (output.data !== undefined) {
console.log(`Data: ${JSON.stringify(output.data, null, 2)}`);
console.log(`Data: ${JSON.stringify(output.data, typesHandler, 2)}`);
}

if (output.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ jobs:
args:
x: "$cases.0.data"
y: "$cases.0.data"
case3:
steps:
- uri: fs/../run-test-wrapper/build
method: returnMap
args:
map:
nested_map:
Hello: 1
Heyo: 50
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Args_add,
Args_addInBox,
Args_addFromEnv,
Args_returnMap,
Num,
Env
} from "./wrap";
Expand All @@ -16,4 +17,8 @@ export function addInBox(args: Args_addInBox): Num {

export function addFromEnv(args: Args_addFromEnv, env: Env): i32 {
return args.x + env.value;
}
}

export function returnMap(args: Args_returnMap): Map<string, Map<string, i32>> {
return args.map;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type Module {
addFromEnv(
x: Int32!
): Int32! @env(required: true)

returnMap(
map: Map! @annotate(type: "Map<String!, Map<String!, Int!>!>!")
): Map! @annotate(type: "Map<String!, Map<String!, Int!>!>!")
}

type Num {
Expand Down