Skip to content
4 changes: 4 additions & 0 deletions actions/setup/js/awf_reflect_summary.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
/// <reference types="@actions/github-script" />

require("./shim.cjs");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice — eagerly requiring ./shim.cjs here ensures core.summary.addRaw()/write() are always defined before main() runs. Consider asserting that the shim is idempotent so repeated requires from other entrypoints stay safe. Automated smoke-test feedback.


const fs = require("fs");

const AWF_CONFIG_PATH = "/tmp/gh-aw/awf-config.json";
Expand Down Expand Up @@ -260,6 +262,8 @@ async function main() {
}

const markdown = buildReflectSummary(reflectData, { awfConfigData, runtimeModelsData });
// shim.cjs ensures core.summary.addRaw()/write() are available in environments
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Smoke review note: good shim use here. It keeps summary output alive when native step-summary APIs missing.

// without native GitHub Actions step-summary support.
await core.summary.addRaw(markdown).write();
core.info("AWF reflect summary written to step summary");
}
Expand Down
30 changes: 30 additions & 0 deletions actions/setup/js/awf_reflect_summary.test.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import fs from "fs";
import { createRequire } from "module";

const require = createRequire(import.meta.url);

const mockCore = {
info: vi.fn(),
Expand Down Expand Up @@ -380,5 +383,32 @@ describe("awf_reflect_summary.cjs", () => {
expect(mockCore.summary.write).toHaveBeenCalledTimes(1);
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("AWF reflect summary written"));
});

it("uses shimmed summary methods when step summary API is missing", async () => {
const originalSummary = global.core.summary;
try {
global.core.summary = undefined;
const shimPath = require.resolve("./shim.cjs");
delete require.cache[shimPath];
require("./shim.cjs");
const addRawSpy = vi.spyOn(global.core.summary, "addRaw");
const writeSpy = vi.spyOn(global.core.summary, "write");
fs.writeFileSync(REFLECT_PATH, JSON.stringify(SAMPLE_REFLECT), "utf8");

await module.main();

expect(addRawSpy).toHaveBeenCalledTimes(1);
expect(writeSpy).toHaveBeenCalledTimes(1);
const summary = addRawSpy.mock.calls[0][0];
expect(summary).toContain("AWF API proxy");
expect(summary).toContain("openai");
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("AWF reflect summary written"));
} finally {
global.core.summary = originalSummary;
const shimPath = require.resolve("./shim.cjs");
delete require.cache[shimPath];
require("./shim.cjs");
}
});
});
});
2 changes: 1 addition & 1 deletion actions/setup/js/pick_experiment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async function writeSummary(assignments, configs, state, core) {
lines.push(`| \`${name}\` | **${selected}** | ${thisCount} / ${totalCount} |`);

const cfg = configs[name] || {};
const minSamples = Number.isInteger(cfg.min_samples) && cfg.min_samples > 0 ? cfg.min_samples : null;
const minSamples = typeof cfg.min_samples === "number" && Number.isInteger(cfg.min_samples) && cfg.min_samples > 0 ? cfg.min_samples : null;
const analysisType = cfg.analysis_type || "n/a";
const tags = Array.isArray(cfg.tags) ? cfg.tags.filter(t => typeof t === "string" && t.length > 0) : [];
const notifyTargets = [];
Expand Down
10 changes: 10 additions & 0 deletions actions/setup/js/shim.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ if (!global.core) {
};
}

const coreSummary = global.core.summary && typeof global.core.summary === "object" ? global.core.summary : (global.core.summary = {});

if (typeof coreSummary.addRaw !== "function") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Smoke review note: this no-op summary fallback is small and safe for non-Actions contexts.

coreSummary.addRaw = () => coreSummary;
}

if (typeof coreSummary.write !== "function") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fallback coreSummary.write = async () => {} silently no-ops in unsupported environments — that's fine, but you may want a debug log so future failures are easier to diagnose. Automated smoke-test feedback.

coreSummary.write = async () => {};
}

if (!global.context) {
// Build a context object from GitHub Actions environment variables,
// mirroring the shape of @actions/github's Context class.
Expand Down
Loading