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
8 changes: 7 additions & 1 deletion packages/software-factory/scripts/boxel-search.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This should be first
import '../src/setup-logger';

import {
fieldPairs,
forceArray,
Expand All @@ -9,6 +12,9 @@ import {
type SearchQuery,
type SearchSort,
} from './lib/boxel';
import { logger } from '../src/logger';

let log = logger('boxel-search');

async function main(): Promise<void> {
let args = parseArgs(process.argv.slice(2));
Expand Down Expand Up @@ -89,6 +95,6 @@ async function main(): Promise<void> {
main().catch((error: unknown) => {
let message =
error instanceof Error ? (error.stack ?? error.message) : String(error);
console.error(message);
log.error(message);
process.exit(1);
});
8 changes: 7 additions & 1 deletion packages/software-factory/scripts/boxel-session.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This should be first
import '../src/setup-logger';

import {
buildBrowserAuth,
buildBrowserSession,
Expand All @@ -6,6 +9,9 @@ import {
parseArgs,
printJson,
} from './lib/boxel';
import { logger } from '../src/logger';

let log = logger('boxel-session');

async function main(): Promise<void> {
let args = parseArgs(process.argv.slice(2));
Expand All @@ -30,6 +36,6 @@ async function main(): Promise<void> {
main().catch((error: unknown) => {
let message =
error instanceof Error ? (error.stack ?? error.message) : String(error);
console.error(message);
log.error(message);
process.exit(1);
});
2 changes: 1 addition & 1 deletion packages/software-factory/scripts/lib/boxel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,5 @@ export function fieldPairs(
}

export function printJson(value: unknown): void {
console.log(JSON.stringify(value, null, 2));
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
}
9 changes: 5 additions & 4 deletions packages/software-factory/scripts/lib/darkfactory-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* are always derived from the actual card definitions.
*/

import { logger } from '../../src/logger';
import type {
ResolvedCodeRef,
LooseSingleCardDocument,
Expand All @@ -23,6 +24,8 @@ import {
// Runtime schema fetching
// ---------------------------------------------------------------------------

let log = logger('darkfactory-schemas');

const GET_CARD_TYPE_SCHEMA_COMMAND =
'@cardstack/boxel-host/commands/get-card-type-schema/default';

Expand Down Expand Up @@ -68,7 +71,7 @@ export async function fetchCardTypeSchema(
);

if (response.status !== 'ready' || !response.result) {
console.warn(
log.warn(
`[darkfactory-schemas] Failed to fetch schema for ${cacheKey}: ${response.error ?? response.status}`,
);
return undefined;
Expand All @@ -85,9 +88,7 @@ export async function fetchCardTypeSchema(
schemaCache.set(cacheKey, result);
return result;
} catch {
console.warn(
`[darkfactory-schemas] Failed to parse schema for ${cacheKey}`,
);
log.warn(`Failed to parse schema for ${cacheKey}`);
return undefined;
}
}
Expand Down
34 changes: 16 additions & 18 deletions packages/software-factory/scripts/lib/factory-implement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import { resolve } from 'node:path';

import { logger } from '../../src/logger';

import type {
KnowledgeArticle,
ProjectCard,
Expand Down Expand Up @@ -71,6 +73,8 @@ import type { FactoryBootstrapResult } from '../../src/factory-bootstrap';
// Constants
// ---------------------------------------------------------------------------

let log = logger('factory-implement');

const PACKAGE_ROOT = resolve(__dirname, '../..');

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -248,10 +252,10 @@ export async function runFactoryImplement(
if (loopResult.outcome === 'tests_passed' || loopResult.outcome === 'done') {
try {
await updateTicketStatus(targetRealmUrl, ticket.id, 'done', fetchOptions);
console.error('[factory-implement] Updated ticket status to done');
log.info('Updated ticket status to done');
} catch (error) {
console.warn(
`[factory-implement] Could not update ticket status: ${
log.warn(
`Could not update ticket status: ${
error instanceof Error ? error.message : String(error)
}`,
);
Expand Down Expand Up @@ -405,9 +409,7 @@ async function fetchCardData(
knowledge.push(card);
} catch {
// Non-fatal: knowledge articles are supplementary
console.warn(
`[factory-implement] Could not fetch knowledge article: ${ka.id}`,
);
log.warn(`Could not fetch knowledge article: ${ka.id}`);
}
}

Expand Down Expand Up @@ -512,9 +514,7 @@ function buildTestRunner(
let start = Date.now();

try {
console.error(
`[factory-implement] Running test file(s) for ticket: ${slug}`,
);
log.info(`Running test file(s) for ticket: ${slug}`);

let handle = await executeTestRunFromRealm({
targetRealmUrl,
Expand All @@ -529,9 +529,7 @@ function buildTestRunner(
});

let durationMs = Date.now() - start;
console.error(
`[factory-implement] Test run complete: status=${handle.status} (${durationMs}ms)`,
);
log.info(`Test run complete: status=${handle.status} (${durationMs}ms)`);

if (handle.status === 'passed') {
return {
Expand Down Expand Up @@ -579,8 +577,8 @@ function buildTestRunner(
}
} catch (error) {
let durationMs = Date.now() - start;
console.error(
`[factory-implement] Test execution error: ${
log.error(
`Test execution error: ${
error instanceof Error ? error.message : String(error)
}`,
);
Expand Down Expand Up @@ -771,8 +769,8 @@ async function loadDarkFactorySchemas(
schemas.set(cardName, schema);
}
} catch (error) {
console.warn(
`[factory-implement] Could not fetch schema for ${cardName}: ${
log.warn(
`Could not fetch schema for ${cardName}: ${
error instanceof Error ? error.message : String(error)
}`,
);
Expand All @@ -792,8 +790,8 @@ async function loadDarkFactorySchemas(
schemas.set(name, schema);
}
} catch (error) {
console.warn(
`[factory-implement] Could not fetch schema for ${name}: ${
log.warn(
`Could not fetch schema for ${name}: ${
error instanceof Error ? error.message : String(error)
}`,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/software-factory/scripts/lib/factory-skill-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class SkillLoader implements SkillLoaderInterface {
results.push(skill);
} catch (error) {
console.warn(
`[SkillLoader] Skipping unavailable skill "${name}": ${
`Skipping unavailable skill "${name}": ${
error instanceof Error ? error.message : String(error)
}`,
);
Expand Down Expand Up @@ -379,7 +379,7 @@ export function enforceSkillBudget(

if (usedTokens + skillTokens > maxTokens) {
console.warn(
`[SkillBudget] Dropping skill "${skill.name}" (${skillTokens} tokens) — ` +
`Dropping skill "${skill.name}" (${skillTokens} tokens) — ` +
`would exceed budget of ${maxTokens} (used: ${usedTokens})`,
);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* (realm protection, per-realm JWT auth, logging).
*/

import { logger } from '../../src/logger';
import type {
LooseSingleCardDocument,
Relationship,
Expand All @@ -31,6 +32,8 @@ import {
// Constants
// ---------------------------------------------------------------------------

let log = logger('factory-tool-builder');

// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -130,7 +133,7 @@ export function buildFactoryTools(
if (schemas?.has(cardName)) {
tools.push(buildFn());
} else {
console.warn(
log.warn(
`[factory-tool-builder] Omitting ${toolName} tool: no schema for ${cardName}`,
);
}
Expand Down
7 changes: 5 additions & 2 deletions packages/software-factory/scripts/lib/realm-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { mkdirSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';

import { logger } from '../../src/logger';
import type { LooseSingleCardDocument } from '@cardstack/runtime-common';
import { APP_BOXEL_REALMS_EVENT_TYPE } from '@cardstack/runtime-common/matrix-constants';
import {
Expand All @@ -19,6 +20,8 @@ import { SupportedMimeType } from '@cardstack/runtime-common/supported-mime-type

export { SupportedMimeType };

let log = logger('realm-operations');

export function ensureTrailingSlash(url: string): string {
return url.endsWith('/') ? url : `${url}/`;
}
Expand Down Expand Up @@ -777,12 +780,12 @@ async function addRealmToMatrixAccountData(
body: JSON.stringify({ realms: existingRealms }),
});
if (!putResponse.ok) {
console.warn(
log.warn(
`Warning: failed to update Matrix account data for realm ${realmUrl}: HTTP ${putResponse.status}`,
);
}
} catch (err) {
console.warn(
log.warn(
`Warning: failed to update Matrix account data for realm ${realmUrl}: ${err instanceof Error ? err.message : String(err)}`,
);
}
Expand Down
20 changes: 11 additions & 9 deletions packages/software-factory/scripts/lib/test-run-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createServer, type Server } from 'node:http';
import { readFileSync } from 'node:fs';
import { normalize, resolve } from 'node:path';

import { logger } from '../../src/logger';

import { chromium } from '@playwright/test';

import { ensureTrailingSlash, searchRealm } from './realm-operations';
Expand All @@ -14,6 +16,8 @@ import type {
TestRunRealmOptions,
} from './test-run-types';

let log = logger('test-run-execution');

// ---------------------------------------------------------------------------
// Resume Logic
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -449,8 +453,8 @@ export async function executeTestRunFromRealm(
});
setHtml(html);

console.error(
`[test-run-execution] Serving QUnit page at ${testPageUrl} for realm ${options.targetRealmUrl}`,
log.info(
`Serving QUnit page at ${testPageUrl} for realm ${options.targetRealmUrl}`,
);

browser = await chromium.launch({ headless: true });
Expand All @@ -459,10 +463,10 @@ export async function executeTestRunFromRealm(
// Forward browser console when debug is enabled
if (options.debug) {
page.on('console', (msg) => {
console.error(`[browser] ${msg.type()}: ${msg.text()}`);
log.debug(`[browser] ${msg.type()}: ${msg.text()}`);
});
page.on('pageerror', (err) => {
console.error(`[browser] PAGE ERROR: ${err.message}`);
log.debug(`[browser] PAGE ERROR: ${err.message}`);
});
}

Expand Down Expand Up @@ -497,8 +501,8 @@ export async function executeTestRunFromRealm(
);

let durationMs = Date.now() - start;
console.error(
`[test-run-execution] QUnit completed in ${durationMs}ms: ${qunitResults.runEnd?.testCounts?.total ?? 0} test(s)`,
log.info(
`QUnit completed in ${durationMs}ms: ${qunitResults.runEnd?.testCounts?.total ?? 0} test(s)`,
);

// Step 3: Parse results and complete the TestRun card.
Expand All @@ -520,9 +524,7 @@ export async function executeTestRunFromRealm(
} catch (err) {
let durationMs = Date.now() - start;
let errorMessage = err instanceof Error ? err.message : String(err);
console.error(
`[test-run-execution] Error: ${errorMessage} (${durationMs}ms)`,
);
log.error(`Error: ${errorMessage} (${durationMs}ms)`);
try {
await completeTestRun(
testRunId,
Expand Down
8 changes: 7 additions & 1 deletion packages/software-factory/scripts/pick-ticket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This should be first
import '../src/setup-logger';

import {
getAccessibleRealmTokens,
matrixLogin,
Expand All @@ -7,6 +10,9 @@ import {
type SearchResultCard,
type SearchSort,
} from './lib/boxel';
import { logger } from '../src/logger';

let log = logger('pick-ticket');

type TicketStatus = 'backlog' | 'in_progress' | 'blocked' | 'review' | 'done';
type TicketPriority = 'critical' | 'high' | 'medium' | 'low';
Expand Down Expand Up @@ -160,6 +166,6 @@ async function main(): Promise<void> {
main().catch((error: unknown) => {
let message =
error instanceof Error ? (error.stack ?? error.message) : String(error);
console.error(message);
log.error(message);
process.exit(1);
});
5 changes: 4 additions & 1 deletion packages/software-factory/scripts/run-realm-tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This should be first
import '../src/setup-logger';

import {
spawnSync,
type SpawnSyncOptionsWithStringEncoding,
Expand Down Expand Up @@ -310,7 +313,7 @@ let summary = {
failures,
};

console.log(JSON.stringify(summary, null, 2));
process.stdout.write(`${JSON.stringify(summary, null, 2)}\n`);

if (testRun.status !== 0) {
process.exit(testRun.status ?? 1);
Expand Down
Loading
Loading