Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devsargam
Copy link
Contributor

@devsargam devsargam commented Mar 9, 2025

Part of #287

The core change is moving from a shared screenshots folder to dedicated folders per test run. This improves organization and makes test results easier to manage and reference.

  • Replace TestCache with TestRun and TestRunRepository system
  • Organize screenshots in dedicated folders per test run
  • Improve test artifact persistence with separate repository directories
  • Improve versioning for test run data formats
  • Implement retention policies for managing test runs

@vercel
Copy link

vercel bot commented Mar 9, 2025

@devsargam is attempting to deploy a commit to the Antiwork Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Mar 9, 2025

CLA assistant check
All committers have signed the CLA.

@devsargam
Copy link
Contributor Author

Currently, I have added new way of taking screenshot but also supporting the older way of doing so. If we don't want backwards compatibility please let me know!

Copy link
Member

@rmarescu rmarescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @devsargam, thanks for the contribution. I've added some comments.

"identifier" in this.testContext.currentTest
) {
const testCase = this.testContext.currentTest as TestCase;
if (testCase.identifier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A testCase always has an identifier, generated via transform. The schema should be updated with a pipe to make it strict()

  // ...
  .transform((data) => {
    const hashInput = `${data.name}:${data.filePath}:${JSON.stringify(data.expectations)}`;
    // Low collision risk for datasets under 65,000 tests
    data.identifier = createHash(hashInput, { length: 8 });
    return data;
  })
  .pipe(z.object({ identifier: z.string() }).strict());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const TestCaseSchema = z
  .object({
    name: z.string(),
    filePath: z.string(),
    payload: z.any().optional(),
    fn: TestCaseFunctionSchema.optional(),
    expectations: z.array(TestCaseExpectationsSchema).default([]),
    beforeFn: TestCaseFunctionSchema.optional(),
    afterFn: TestCaseFunctionSchema.optional(),
    directExecution: z.boolean().optional().default(false),
    identifier: z.string().optional(),
  })
  .strict()
  .transform((data) => {
    const hashInput = `${data.name}:${data.filePath}:${JSON.stringify(data.expectations)}`;
    // Low collision risk for datasets under 65,000 tests
    data.identifier = createHash(hashInput, { length: 8 });
    return data;
  });

Here, regardless of whether user passes identifier or not, the original is going to be overwritten by what's there in the transform? Is this intentional?

@rmarescu rmarescu added this to the v0.4.7 milestone Mar 12, 2025
rmarescu added a commit that referenced this pull request Mar 13, 2025
In preparation for #387

Extract test execution state management into a dedicated `TestRun`
class, replacing the previous `TestResult` type. This improves
encapsulation of test state transitions (pending -> running ->
passed/failed) and token usage tracking.
In #387, `TestRun` will be used to set the timestamp when the test runs
starts, so that can it can be used to store screenshots in a folder
having the same name as the test run cache file.
@devsargam
Copy link
Contributor Author

devsargam commented Mar 13, 2025

TODOS:

  • figure out way to delete screenshots inside directory with MAX_SCREENSHOT_LIMIT
  • Figure out why legacy screenshot directory is being created
  • Use fs/promises consistently throughout changes
  • test changes thoroughly

@devsargam devsargam requested a review from rmarescu March 13, 2025 09:21
@vercel
Copy link

vercel bot commented Mar 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
shortest ⬜️ Ignored (Inspect) Visit Preview Mar 14, 2025 7:19am

Copy link
Member

@rmarescu rmarescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced TestRun and TestRunRepository to expand the basic functionality of cached data towards baselines.

I'll do a final check tomorrow before merging.

};

case InternalActionEnum.RUN_CALLBACK: {
if (!this.testContext?.currentTest) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testContext must always be present.

this.testContext = newContext;
}

private cleanupScreenshots(): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestRunRepository deals with cleaning up unwanted runs now.

Comment on lines +65 to +67
const testFileExists = existsSync(
path.join(process.cwd(), entry.test.filePath),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rudimentary check if the entry is orphaned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced mostly by TestRunRepository

Comment on lines -105 to -106
const testRun = new TestRun(testCase);
testRun.markRunning();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now initialized by the caller of this function.

};

export class TestRunRepository {
public static VERSION = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased from 1 previously, and using numbers now. Generally, test runs with previous versions are automatically discarted, their metadata is different.

(testRun) =>
testRun.status === "passed" &&
testRun.version === TestRunRepository.VERSION &&
!testRun.fromCache,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test runs from cache don't have AI steps, so they are not useful for executing future runs off them.

}
// If no passed run, keep only up to MAX_RUNS_PER_TEST most recent runs
else {
const MAX_RUNS_PER_TEST = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be easily changed to keep multiple copies if needed.

testRun.runId = cacheEntry.metadata.runId;
testRun.timestamp = cacheEntry.metadata.timestamp;
testRun.version =
typeof cacheEntry.metadata.version === "string"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handles the previous version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated, haven't reviewed the tests.

@devsargam
Copy link
Contributor Author

okay, let me know if I need to make any changes

@rmarescu rmarescu merged commit 3094d9a into antiwork:main Mar 14, 2025
4 of 5 checks passed
@github-project-automation github-project-automation bot moved this to Done in Shortest Mar 14, 2025
@devsargam devsargam deleted the cache-5 branch March 15, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants