-
Notifications
You must be signed in to change notification settings - Fork 13
Run against a base URL that scopes paths and pins query params #231
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
Open
DavertMik
wants to merge
7
commits into
main
Choose a base branch
from
run-base-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1e5f85
docs: design spec for mdq standalone package
ad7c8f4
docs: resolve open questions in mdq spec
a0dc4a7
docs: implementation plan for mdq package
e6720f7
Merge branch 'main' of github.com:testomatio/explorbot
7a348d5
Merge branch 'main' of github.com:testomatio/explorbot
3444cbe
feat(cli): run against a base URL that scopes paths and pins query pa…
e16740d
Merge remote-tracking branch 'origin/main' into run-base-url
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,6 +325,7 @@ export class ConfigParser { | |
| private site: SiteRecord | null = null; | ||
| private siteStartPath = '/'; | ||
| private siteConfigPath: string | null = null; | ||
| private runBase: RunBase | null = null; | ||
|
|
||
| private constructor() {} | ||
|
|
||
|
|
@@ -366,6 +367,7 @@ export class ConfigParser { | |
| if (this.config && !options?.config && !options?.path && this.runtimeTarget === target) { | ||
| return this.config; | ||
| } | ||
| this.runBase = parseRunBase(options?.baseUrl); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In config-free mode, EXPLORBOT_URL still wins when selecting the output root. With both values set, --base-url changes the browser origin but knowledge, experience, and output can come from the wrong site |
||
|
|
||
| // Store the initial working directory for reference | ||
| if (!process.env.INITIAL_CWD) { | ||
|
|
@@ -409,7 +411,7 @@ export class ConfigParser { | |
| log(`Configuration built from EXPLORBOT_* environment variables. Output: ${outputRoot}`); | ||
| } | ||
|
|
||
| let config = this.resolveConfig(loadedConfig as ExplorbotConfig, options); | ||
| let config = this.resolveConfig(loadedConfig as ExplorbotConfig); | ||
| await resolveConfigModels(config.ai); | ||
| this.site = null; | ||
| this.siteConfigPath = null; | ||
|
|
@@ -481,6 +483,18 @@ export class ConfigParser { | |
| return this.siteConfigPath; | ||
| } | ||
|
|
||
| public applyBasePath(target: string): string { | ||
| const base = this.runBase?.path; | ||
| if (!base) return target; | ||
| if (!target.startsWith('/')) return target; | ||
| if (target === base || target.startsWith(`${base}/`) || target.startsWith(`${base}?`)) return target; | ||
| return `${base}${target}`; | ||
| } | ||
|
|
||
| public getBaseQuery(): string { | ||
| return this.runBase?.query || ''; | ||
| } | ||
|
|
||
| public resolveTargetPath(target?: string): string { | ||
| if (!this.site) { | ||
| const configured = this.config?.playwright?.url || this.config?.web?.url; | ||
|
|
@@ -489,12 +503,13 @@ export class ConfigParser { | |
| if (targetOrigin && baseOrigin && targetOrigin !== baseOrigin) { | ||
| tag('warning').log(`Exploring ${targetOrigin} but base URL is ${baseOrigin}. Relative navigation resolves against the base URL — set web.url to ${targetOrigin} to avoid it.`); | ||
| } | ||
| return target || '/'; | ||
| return this.applyBasePath(target || '/'); | ||
| } | ||
| if (!target) return this.siteStartPath; | ||
|
|
||
| const resolved = resolveSiteTarget(target, this.site.url); | ||
| if (resolved.baseUrl !== this.site.url) return target; | ||
| if (target.startsWith('/')) return this.applyBasePath(resolved.path); | ||
| return resolved.path; | ||
| } | ||
|
|
||
|
|
@@ -521,6 +536,7 @@ export class ConfigParser { | |
| ConfigParser.instance.site = null; | ||
| ConfigParser.instance.siteStartPath = '/'; | ||
| ConfigParser.instance.siteConfigPath = null; | ||
| ConfigParser.instance.runBase = null; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -683,15 +699,15 @@ export class ConfigParser { | |
| } | ||
| } | ||
|
|
||
| private resolveConfig(config: ExplorbotConfig, options?: { baseUrl?: string }): ExplorbotConfig { | ||
| private resolveConfig(config: ExplorbotConfig): ExplorbotConfig { | ||
| if (config.web?.url && !config.playwright?.url) { | ||
| config.playwright = config.playwright || { browser: 'chromium', url: '' }; | ||
| config.playwright.url = config.web.url; | ||
| } | ||
|
|
||
| if (options?.baseUrl) { | ||
| if (this.runBase) { | ||
| config.playwright = config.playwright || { browser: 'chromium', url: '' }; | ||
| config.playwright.url = options.baseUrl; | ||
| config.playwright.url = this.runBase.origin; | ||
| } | ||
|
|
||
| resolveLangfuse(config.ai); | ||
|
|
@@ -925,8 +941,23 @@ export async function createModel(provider: string, modelId: string): Promise<an | |
| return (await info.load())(modelId); | ||
| } | ||
|
|
||
| function parseRunBase(baseUrl?: string): RunBase | null { | ||
| if (!baseUrl) return null; | ||
|
|
||
| const url = URL.parse(baseUrl); | ||
| if (!url) throw new Error(`Base URL must be a full URL like https://app.example.com/team/acme, got "${baseUrl}"`); | ||
|
|
||
| return { origin: url.origin, path: url.pathname.replace(/\/+$/, ''), query: url.search }; | ||
| } | ||
|
|
||
| type ModelRole = 'model' | 'visionModel' | 'agenticModel'; | ||
|
|
||
| interface RunBase { | ||
| origin: string; | ||
| path: string; | ||
| query: string; | ||
| } | ||
|
|
||
| interface ConfiguredModel { | ||
| name: string; | ||
| provider: string; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also exposes --base-url to rerun, but rerun executes saved I.amOnPage() calls directly through Mocha, bypassing the new path-scoping logic