Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: e2e agent process #74

Merged
merged 13 commits into from
Oct 28, 2024
Merged

chore: e2e agent process #74

merged 13 commits into from
Oct 28, 2024

Conversation

0xyaco
Copy link
Collaborator

@0xyaco 0xyaco commented Oct 25, 2024

🤖 Linear

Closes GRT-234

Description

Given that the agent is an "infinite loop" we need to wrap it inside a forked process during each E2E scenario to be able to kill it whenever the test is completed.

Create a spawnAgent util function that allows the developer to spawn agents inside processes to be able to terminate them.

Copy link

linear bot commented Oct 25, 2024

@0xyaco 0xyaco changed the title Chore/e2e agent process chore: e2e agent process Oct 25, 2024
Copy link
Collaborator

@jahabeebs jahabeebs left a comment

Choose a reason for hiding this comment

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

ᕕ(⌐■_■)ᕗ ♪♬

Comment on lines 23 to 30
const agentProcess = spawn("pnpm", ["start"], {
env: {
...process.env,
...env,
PROTOCOL_PROVIDER_L1_RPC_URLS: env.PROTOCOL_PROVIDER_L1_RPC_URLS.toString(),
PROTOCOL_PROVIDER_L2_RPC_URLS: env.PROTOCOL_PROVIDER_L2_RPC_URLS.toString(),
BLOCK_NUMBER_RPC_URLS_MAP: blockNumberUrls,
EBO_AGENT_CONFIG_FILE_PATH: path,
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

😮 never used spawn but sounds cool, i've always worked with exec since scripts aren't long lived

curious: spawn is not async, so on return the Agent is supposed to be full-up? isn't any delay we should make?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a super interesting question; I'm no spawn specialist but it looks like the function returns just right after creating the process, so we have no idea at that moment if the agent is already doing stuff or it's being initialized.

We could listen for its stdout, waiting for some log (ie "Agent started..." or something like that) to ensure that the agent has started; the good thing about our current E2E approach is that the only way for it to pass it's for the agent to boot up and start generating events. If it does not, it will just time-out and fail.

const generateConfigFile = (path: string, config: AgentConfig) => {
const content = yaml.stringify(config);

fs.writeFileSync(path, content, "utf-8");
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't want to delete the generated file after test finishes? (i assume tmp path are git-ignored)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like it!

export const spawnAgent = (params: { config: AgentConfig; env: AgentEnv }) => {
const { config, env } = params;

const path = "/tmp/config.test.yaml";
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about doing

path.join(__dirname, "/tmp/config.test.yaml");

@0xyaco 0xyaco force-pushed the chore/e2e-agent-process branch from 28da2b4 to d0941a9 Compare October 28, 2024 12:28
0xnigir1
0xnigir1 previously approved these changes Oct 28, 2024
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

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

nice, lgtm now 🚀


afterAll(() => {
fs.rmSync(tmpConfigDir, { recursive: true, force: true });
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

💎

jahabeebs
jahabeebs previously approved these changes Oct 28, 2024
Base automatically changed from fix/approved-modules to dev October 28, 2024 13:00
@0xyaco 0xyaco dismissed stale reviews from jahabeebs and 0xnigir1 October 28, 2024 13:00

The base branch was changed.

@0xyaco 0xyaco merged commit 2705b91 into dev Oct 28, 2024
5 checks passed
@0xyaco 0xyaco deleted the chore/e2e-agent-process branch October 28, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants