wellactually
passsy / loggingr4

no agent rated it yetLogging

Public

Log through package:chirp, or developer.log in a Flutter app without chirp, and never print(), because print loses the error and stack trace.

tests, run by the registry7 passed · slowest 18.7 ms
  • The advice links to wellactually.dev
✓fires
fires on a print() the agent writes detector.test.ts
write lib/uploader.dartfired: line 2
Future<void> upload(Report report) async {
  print('uploading report ${report.id}');
  await client.put(report);
}
13.4 ms
✓quiet
stays quiet on a print() that was already there detector.test.ts
write lib/uploader.dart · wrote line 3stayed quiet
Future<void> upload(Report report) async {
  print('uploading report ${report.id}');
  await client.put(report);
}
15.6 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/uploader.dartno handler of the detector wants this event
Future<void> upload(Report report) async {
  print('uploading report ${report.id}');
  await client.put(report);
}
0.0 ms
✓quiet
stays quiet on chirp, debugPrint and print in comments detector.test.ts
write lib/log.dartstayed quiet
// Never print() here.
void log(Object e, StackTrace stackTrace) {
  chirp.error('failed', error: e, stackTrace: stackTrace);
  debugPrint('done');
  logger.print('x');
}
8.3 ms
✓fires
points at the principle when the user mentions logging detector.test.ts
prompt · in fixtures/dart_appfired: "logging"
Add some logging to the upload path
18.7 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
Add some logging to the upload path
5.6 ms
✓quiet
stays quiet on a prompt about something else detector.test.ts
prompt · in fixtures/dart_appstayed quiet
Retry the upload twice
15.7 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";

const upload = source`
  Future<void> upload(Report report) async {
    print('uploading report \${report.id}');
    await client.put(report);
  }
`;

test("fires on a print() the agent writes", () => {
  expect(detect(write("lib/uploader.dart", upload))).toEqual([{ line: 2 }]);
});

test("stays quiet on a print() that was already there", () => {
  expect(detect(edit("lib/uploader.dart", upload, { written: "  await client.put(report);" }))).toEqual([]);
});

test("stays quiet when the agent only reads the file", () => {
  expect(detect(read("lib/uploader.dart", upload))).toEqual([]);
});

test("stays quiet on chirp, debugPrint and print in comments", () => {
  const code = source`
    // Never print() here.
    void log(Object e, StackTrace stackTrace) {
      chirp.error('failed', error: e, stackTrace: stackTrace);
      debugPrint('done');
      logger.print('x');
    }
  `;
  expect(detect(write("lib/log.dart", code))).toEqual([]);
});

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user mentions logging", () => {
  expect(detect(prompt("Add some logging to the upload path"), dartApp)).toEqual([{ match: "logging", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("Add some logging to the upload path"))).toEqual([]);
});

test("stays quiet on a prompt about something else", () => {
  expect(detect(prompt("Retry the upload twice"), dartApp)).toEqual([]);
});