Skip to content
Draft
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
14 changes: 3 additions & 11 deletions actions/setup/js/write_daily_aic_usage_cache.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ const USAGE_DIR = "/tmp/gh-aw/usage";
* @param {Record<string, unknown>} [details]
*/
function logCache(message, details) {
let suffix = "";
if (details && Object.keys(details).length > 0) {
try {
suffix = ": " + JSON.stringify(details);
} catch (e) {
core.warning(`[daily-aic-cache] logCache: could not serialise details: ${e}`);
suffix = ": {}";
}
}
const suffix = details && Object.keys(details).length > 0 ? ": " + JSON.stringify(details) : "";
core.info(`[daily-aic-cache] ${message}${suffix}`);
}

Expand All @@ -58,8 +50,8 @@ function logCache(message, details) {
* @returns {Promise<void>}
*/
async function mainWithPaths(cacheFilePath, usageDir) {
const cachePath = cacheFilePath || CACHE_FILE_PATH;
const usageDirPath = usageDir || USAGE_DIR;
const cachePath = cacheFilePath ?? CACHE_FILE_PATH;
const usageDirPath = usageDir ?? USAGE_DIR;
try {
const runId = Number(process.env.GITHUB_RUN_ID || 0);
if (!runId) {
Expand Down
8 changes: 8 additions & 0 deletions actions/setup/js/write_daily_aic_usage_cache.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ describe("write_daily_aic_usage_cache", () => {
expect(entry.aic).toBe(3.0);
});

it("writes a large AIC value correctly", async () => {
writeUsageFile(999.99);
await runMain();
const entry = JSON.parse(fs.readFileSync(cacheFile, "utf8").trim());
expect(entry.aic).toBe(999.99);
expect(global.core.warning).not.toHaveBeenCalled();
});

it("emits a warning and does not crash when the existing cache file cannot be read", async () => {
// Creating a directory at the cache path causes readFileSync to throw EISDIR
fs.mkdirSync(cacheFile);
Expand Down