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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ concurrency:
cancel-in-progress: true

jobs:
format:
name: Formatting
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: npm

- name: Install dependencies
run: npm ci

- name: Check formatting
run: npm run format:check

test:
name: Node ${{ matrix.node-version }}
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node_modules/

dist/
build/
tsconfig.tsbuildinfo
*.tsbuildinfo

# Logs

Expand Down
8 changes: 5 additions & 3 deletions .husky/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Run a quick check - you can add linting here later
# For now, we'll just echo a message since tests are in pre-push
echo "Pre-commit hook: Ready for linting/formatting checks"
set -e

git --no-pager diff --cached --check
npm exec -- lint-staged
npm run typecheck
12 changes: 11 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
packages/core/src/views/diff.ejs
dist/
coverage/
storage/
snapshots/
comparisons/
.local-breakcheck-packages/
docs/plans/
packages/core/src/public/css/diff2html.min.css
packages/core/src/public/js/diff2html.min.js

packages/core/src/views/diff.ejs
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"printWidth": 80
}
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ Compares two snapshots, applies rules, and saves the results.
breakcheck compare [options]
```

| Option | Description | Default |
| :-------------------- | :------------------------------------------------------------ | :---------------- |
| `-b, --before <name>` | **(Required)** The name of the "before" snapshot. | |
| `-a, --after <name>` | **(Required)** The name of the "after" snapshot. | |
| `-o, --output <name>` | A name for the comparison output directory. | `compare_default` |
| `-r, --rules <directory>` | Directory containing `rules.breakcheck`; relative paths resolve from the directory where Breakcheck is invoked. | None (unfiltered comparison) |
| `--json-logs` | Output logs in JSON format (useful for automation). | |
| `--no-json-logs` | Output logs in pretty format (default, user-friendly). | |
| Option | Description | Default |
| :------------------------ | :-------------------------------------------------------------------------------------------------------------- | :--------------------------- |
| `-b, --before <name>` | **(Required)** The name of the "before" snapshot. | |
| `-a, --after <name>` | **(Required)** The name of the "after" snapshot. | |
| `-o, --output <name>` | A name for the comparison output directory. | `compare_default` |
| `-r, --rules <directory>` | Directory containing `rules.breakcheck`; relative paths resolve from the directory where Breakcheck is invoked. | None (unfiltered comparison) |
| `--json-logs` | Output logs in JSON format (useful for automation). | |
| `--no-json-logs` | Output logs in pretty format (default, user-friendly). | |

### `view`

Expand All @@ -242,11 +242,11 @@ breakcheck view [comparison-name] [options]
| :---------------- | :---------------------------------- | :---------------- |
| `comparison-name` | The name of the comparison to view. | `compare_default` |

| Option | Description | Default |
| :-------------------- | :----------------------------------------------------- | :------ |
| Option | Description | Default |
| :-------------------- | :------------------------------------------------------------------------------------------------- | :---------------------- |
| `-p, --port <number>` | The port to run the view server on. When omitted, starts at 8080 and uses the next available port. | `8080` (next available) |
| `--json-logs` | Output logs in JSON format (useful for automation). | |
| `--no-json-logs` | Output logs in pretty format (default, user-friendly). | |
| `--json-logs` | Output logs in JSON format (useful for automation). | |
| `--no-json-logs` | Output logs in pretty format (default, user-friendly). | |

### `list-snapshots`

Expand Down Expand Up @@ -300,6 +300,11 @@ All commands support these logging options:
| `--json-logs` | Output logs in JSON format (useful for automation) | |
| `--no-json-logs` | Output logs in pretty format (user-friendly) | ✓ |

Snapshot crawler lifecycle and error messages use the same logger as Breakcheck's
command messages. This means `--json-logs` also produces structured JSON for
Crawlee records, including a `component` field such as `CheerioCrawler`; the
default pretty output includes timestamps for both sources.

### Use Cases

- **Interactive use**: Use the default pretty logging for easy reading during development and testing
Expand Down
16 changes: 8 additions & 8 deletions docs/development-and-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ npm run build

The main development commands are:

| Command | Purpose |
| --- | --- |
| `npm test` | Run the unit and component test suite once. |
| `npm run test:watch` | Run Vitest in watch mode while developing. |
| `npm run test:coverage` | Run the tests with V8 coverage. |
| `npm run test:cli-bin` | Build the CLI and invoke its compiled executable with native Node. |
| `npm run test:integration` | Build the project, start the before/after fixture servers, run snapshots and comparisons, and verify the viewer. |
| `npm run test:packaging` | Pack the core and CLI workspaces, install them in a temporary consumer with no `tsx`, and exercise the installed CLI, core import, snapshots, comparisons, and viewer. |
| Command | Purpose |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `npm test` | Run the unit and component test suite once. |
| `npm run test:watch` | Run Vitest in watch mode while developing. |
| `npm run test:coverage` | Run the tests with V8 coverage. |
| `npm run test:cli-bin` | Build the CLI and invoke its compiled executable with native Node. |
| `npm run test:integration` | Build the project, start the before/after fixture servers, run snapshots and comparisons, and verify the viewer. |
| `npm run test:packaging` | Pack the core and CLI workspaces, install them in a temporary consumer with no `tsx`, and exercise the installed CLI, core import, snapshots, comparisons, and viewer. |

The integration test owns the fixture-server lifecycle. It starts the
before-version server, takes a snapshot, replaces it with the after-version
Expand Down
32 changes: 32 additions & 0 deletions docs/plans/2026-08-31-12-18/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Crawlee Logger Injection Plan

## Dates

- Plan created: 2026-08-31 (planning files first recorded during the implementation session)
- Archived: 2026-08-31 12:18 (America/Toronto)

## Goal

Route Crawlee lifecycle and crawler error logs through the selected Breakcheck
Pino logger so snapshot output has one formatter, honors `--json-logs`, and does
not emit duplicate lines.

## Accomplished

- Added a core-owned Crawlee-to-Pino adapter with severity, component, structured
field, suffix, and exception forwarding.
- Updated the shared core logger and CLI configuration so Crawlee and core error
messages follow the selected pretty or JSON transport.
- Added focused unit coverage and fixture integration coverage for formatting,
level mapping, JSON error paths, and duplicate suppression.
- Updated root, CLI, and core logging documentation.
- Verified unit, integration, compiled CLI, and fresh-install packaging checks.

## Related Work

- Commit: [6c05336](https://github.com/cleaver/breakcheck/commit/6c05336)
- Pull request: [#7](https://github.com/cleaver/breakcheck/pull/7)
- Branch: `feat/inject-crawlee-logger`

The original planning files were copied here and remain in the project root for
user confirmation before deletion.
65 changes: 65 additions & 0 deletions docs/plans/2026-08-31-12-18/findings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Findings & Decisions

## Requirements

- Inject the selected Breakcheck Pino logger into Crawlee.
- Make Crawlee's crawler lifecycle output honor the CLI's pretty/JSON logging mode.
- Preserve useful log levels, crawler prefixes, structured data, and exceptions.
- Avoid duplicate output from Crawlee's existing console logger.
- Keep the change compatible with the core API and REST/server logger usage.
- Add focused regression coverage and update user-facing logging documentation.

## Research Findings

- `packages/core/src/lib/logger.ts` creates Breakcheck's Pino logger. Pretty mode uses `pino-pretty` with `translateTime: "SYS:standard"`; JSON mode uses Pino's standard JSON output.
- `packages/cli/src/cli/utils.ts` creates a new Pino logger inside `configureLogger()`. The CLI command uses that returned logger for result messages.
- `packages/core/src/core/crawler/index.ts` calls `this.crawler.run(...)`; the lifecycle messages are emitted inside Crawlee, not by Breakcheck's `logger` wrapper.
- `packages/core/src/core/crawler/implementations/cheerio.ts` and the Playwright implementation construct Crawlee crawler instances without passing a logger.
- The installed Crawlee 3.18.1 package re-exports the global `@apify/log` instance and its `Logger`/`LoggerText`/`LoggerJson` extension classes.
- `@apify/log`'s default `LoggerText` has `skipTime: true`. Its `Log.setOptions({ logger })` API accepts a replacement logger, and its documentation explicitly supports custom logger implementations.
- Crawlee's `BasicCrawler` emits the observed messages through `this.log.info(...)`; replacing the underlying `@apify/log` logger is therefore sufficient to stop the original text output and route the calls elsewhere.
- Crawlee's numeric levels are `ERROR=1`, `SOFT_FAIL=2`, `WARNING=3`, `INFO=4`, `DEBUG=5`, and `PERF=6`. Pino has no exact `SOFT_FAIL` or `PERF` equivalents, so those require an explicit mapping.
- A successful fixture crawl reproduced the reported split. Adding `--json-logs` changed only Breakcheck's final lines; Crawlee's lines remained colored text, confirming the two logger paths are independent.
- Core modules import the exported `logger` singleton directly. Replacing only the CLI-local logger can leave core error messages on the original default Pino instance, so logger ownership should be addressed as part of implementation.
- There are currently no dedicated logger tests in `packages/*/src/__tests__`; the new tests should establish that seam.

## Technical Decisions

| Decision | Rationale |
|----------|-----------|
| Use Crawlee's replacement-logger extension point | It preserves the structured call boundary and avoids parsing rendered text. |
| Implement the adapter in core | The Crawlee dependency belongs to `@cleaver/breakcheck-core`; this avoids adding a direct Crawlee dependency to the published CLI. |
| Install the adapter before crawler construction/execution | It guarantees lifecycle logs use the selected Pino logger from the first crawler message. |
| Map `ERROR→error`, `WARNING→warn`, `INFO→info`, `DEBUG→debug` | These mappings preserve the closest Pino severity. |
| Map `SOFT_FAIL→warn` and `PERF→debug` initially | Pino has no matching names; warning keeps soft failures visible, while performance diagnostics should not become normal informational output. Confirm with tests/documentation. |
| Preserve Crawlee's prefix as structured metadata and readable context | This keeps fields queryable in JSON while retaining `CheerioCrawler`/`PlaywrightCrawler` context in terminal output. |
| Do not use `log.on("line")` or intercept `console.*` | Those approaches observe already-rendered output, risk double emission, and lose original severity/fields. |
| Prefer one explicit logging configuration entrypoint over side effects in `createLogger()` | A logger factory should not unexpectedly reconfigure Crawlee's process-global logger every time it is called. |
| Make the exported core logger a live binding updated by `configureLogger()` | Core modules import the logger directly; updating the exported binding lets validation and other core error paths honor CLI-selected JSON/pretty mode. |
| Configure the default core logger for Crawlee at module initialization | Programmatic core consumers get a consistent default without requiring CLI-only setup. |

## Issues Encountered

| Issue | Resolution |
|-------|------------|
| Default sandbox prevented the local fixture from listening | Used approved local-network access for reproduction; no repository code was changed. |
| CLI Pino logger and core default logger are separate instances | Include shared logger/configuration handling in the implementation phase rather than adapting Crawlee alone. |

## Resources

- `packages/core/src/lib/logger.ts`
- `packages/cli/src/cli/utils.ts`
- `packages/cli/src/cli/commands/snapshot.ts`
- `packages/core/src/core/crawler/index.ts`
- `packages/core/src/core/crawler/implementations/cheerio.ts`
- `packages/core/src/core/crawler/implementations/playwright.ts`
- `packages/core/src/index.ts`
- `packages/cli/src/__tests__/setup.test.ts`
- `scripts/test-integration.mjs`
- `scripts/test-packaging.mjs`
- `node_modules/@crawlee/core/log.d.ts`
- `node_modules/@apify/log/esm/index.d.mts`

## Visual/Browser Findings

- None.
Loading
Loading