feat(browser,mcp): resolve environment and credentials from DB in exec

- POST /exec now accepts environmentId (UUID) and credentials (alias → UUID)
  instead of raw payloads; resolves entities via EnvironmentService and
  CredentialService before passing data to browserService.exec
- exec_code MCP tool updated with same schema: environmentId + credentials map
- CredentialModule imported into BrowserModule and McpModule
- docs(scenario): rewrite script runtime section for single context argument
- docs(mcp): update exec_code description to reflect new parameter shapes
- style: reorder imports across server source (formatter)
This commit is contained in:
2026-04-14 18:09:28 +03:00
parent 90be5a5490
commit 0e47623a6b
48 changed files with 268 additions and 211 deletions
+19 -15
View File
@@ -17,24 +17,28 @@ Current scheduler behavior is exec-centric:
## Script runtime
`execCode` and `validateCode` execute as async JavaScript with:
`execCode` and `validateCode` execute as async JavaScript with a single `context` argument:
- `page`: Playwright `Page`
- `context`: Playwright `BrowserContext`
- `helpers`: utility object
```js
async (context) => {
// your code here
}
```
Available in scope:
- `context.page`: Playwright `Page`
- `context.browser`: Playwright `BrowserContext`
- `context.env`: shallow copy of environment key/value map
- `context.getEnv(key)`: required environment value lookup (throws if missing)
- `context.getCredential(alias)`: credential payload assigned to the scenario alias
- `context.getStepOutput(order)`: prior step output by absolute order (`1`, `2`, ...) or relative (`-1` = previous step)
- `context.dumpDom(selector?)`: simplified DOM snapshot
- `context.log(...args)`, `context.warn(...args)`, `context.error(...args)`: structured step logs
- `context.runSnippet(name, ...args)`: execute stored snippet code with the same context
- `console`: proxied to run logs (`log`, `warn`, `error`, etc.)
`validateCode` additionally receives `result`, which is the value returned by `execCode`.
## Available helpers
- `helpers.dumpDom(selector?)`: simplified DOM snapshot
- `helpers.log(...args)`, `helpers.warn(...args)`, `helpers.error(...args)`: structured step logs
- `helpers.getStepOutput(order)`: prior step output by absolute order (`0`, `1`, ...) or relative (`-1` previous step)
- `helpers.getCredential(alias)`: credential payload assigned to the scenario alias
- `helpers.env`: shallow copy of environment URL map
- `helpers.getEnv(key)`: required environment value lookup (throws if missing)
- `helpers.runSnippet(name, ...args)`: execute stored snippet code in the same page/context/helpers scope
`validateCode` additionally receives `result` in scope, which is the value returned by `execCode`.
## Validation contract