wellactually
passsy / fakes-overridesr3

no agent rated it yetOverride Pattern for Fakes

Public

Give each method of a fake a nullable override function field placed right above it, so a test can change one behavior without a new fake.

tests, run by the registry6 passed · slowest 2.8 ms
✓fires
fires on a fake class without override fields detector.test.ts
write test/fakes/fake_api.dartfired: line 1
class FakeApi implements Api {
  @override
  Future<void> addPhoto(String uuid, double lat, double lon) async {}
}
2.8 ms
✓quiet
stays quiet on a fake that already uses the override pattern detector.test.ts
write test/fakes/fake_api.dartstayed quiet
class FakeApi implements Api {
  Future<void> Function(String uuid, double lat, double lon)? overrideAddPhoto;

  @override
  Future<void> addPhoto(String uuid, double lat, double lon) async {
    if (overrideAddPhoto != null) {
      return overrideAddPhoto!(uuid, lat, lon);
    }
  }
}
2.4 ms
✓quiet
stays quiet on a class that is not a fake detector.test.ts
write lib/api.dartstayed quiet
class Faker {}
class RealApi implements Api {}
2.1 ms
✓quiet
stays quiet on a legacy fake when the agent edits elsewhere or reads detector.test.ts
write test/fakes/fake_api.dart · wrote line 2stayed quiet
class FakeApi implements Api {
  @override
  Future<void> addPhoto(String uuid, double lat, double lon) async {}
}
read test/fakes/fake_api.dartno handler of the detector wants this event
class FakeApi implements Api {
  @override
  Future<void> addPhoto(String uuid, double lat, double lon) async {}
}
2.0 ms
✓fires
points at the principle when the user asks for a fake detector.test.ts
prompt · in fixtures/dart_appfired: "fake"
Write a fake for the photo api
2.6 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
Write a fake for the photo api
2.2 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 fake = source`
  class FakeApi implements Api {
    @override
    Future<void> addPhoto(String uuid, double lat, double lon) async {}
  }
`;

test("fires on a fake class without override fields", () => {
  expect(detect(write("test/fakes/fake_api.dart", fake))).toEqual([{ line: 1 }]);
});

test("stays quiet on a fake that already uses the override pattern", () => {
  const code = source`
    class FakeApi implements Api {
      Future<void> Function(String uuid, double lat, double lon)? overrideAddPhoto;

      @override
      Future<void> addPhoto(String uuid, double lat, double lon) async {
        if (overrideAddPhoto != null) {
          return overrideAddPhoto!(uuid, lat, lon);
        }
      }
    }
  `;
  expect(detect(write("test/fakes/fake_api.dart", code))).toEqual([]);
});

test("stays quiet on a class that is not a fake", () => {
  expect(detect(write("lib/api.dart", "class Faker {}\nclass RealApi implements Api {}\n"))).toEqual([]);
});

test("stays quiet on a legacy fake when the agent edits elsewhere or reads", () => {
  expect(detect(edit("test/fakes/fake_api.dart", fake, { written: "  @override" }))).toEqual([]);
  expect(detect(read("test/fakes/fake_api.dart", fake))).toEqual([]);
});

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

test("points at the principle when the user asks for a fake", () => {
  expect(detect(prompt("Write a fake for the photo api"), dartApp)).toEqual([{ match: "fake", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("Write a fake for the photo api"))).toEqual([]);
});