1
1
import path from "node:path" ;
2
- import { type Locator , expect , test } from "@playwright/test" ;
2
+ import { type Locator , expect , test , Page } from "@playwright/test" ;
3
3
import { users } from "../../constants" ;
4
4
import {
5
5
currentUser ,
@@ -54,9 +54,7 @@ test("create template with desired prebuilds", async ({ page, baseURL }) => {
54
54
await waitForExpectedCount ( prebuilds , expectedPrebuilds ) ;
55
55
56
56
// Wait for prebuilds to start.
57
- const runningPrebuilds = page
58
- . getByTestId ( "build-status" )
59
- . getByText ( "Running" ) ;
57
+ const runningPrebuilds = runningPrebuildsLocator ( page ) ;
60
58
await waitForExpectedCount ( runningPrebuilds , expectedPrebuilds ) ;
61
59
} ) ;
62
60
@@ -86,15 +84,15 @@ test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
86
84
) ;
87
85
88
86
// Wait for prebuilds to start.
89
- let runningPrebuilds = page . getByTestId ( "build-status" ) . getByText ( "Running" ) ;
87
+ let runningPrebuilds = runningPrebuildsLocator ( page ) ;
90
88
await waitForExpectedCount ( runningPrebuilds , expectedPrebuilds ) ;
91
89
92
90
// Open the first prebuild.
93
91
await runningPrebuilds . first ( ) . click ( ) ;
94
92
await page . waitForURL ( / \/ @ p r e b u i l d s \/ p r e b u i l d - .+ / ) ;
95
93
96
94
// Wait for the prebuild to become ready so it's eligible to be claimed.
97
- await page . getByTestId ( "agent-status-ready" ) . waitFor ( { timeout : 60_000 } ) ;
95
+ await page . getByTestId ( "agent-status-ready" ) . waitFor ( { timeout : 120_000 } ) ;
98
96
99
97
// Logout as admin, and login as an unprivileged user.
100
98
await login ( page , users . member ) ;
@@ -127,12 +125,19 @@ test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
127
125
timeout : waitForBuildTimeout , // Account for workspace build time.
128
126
} ) ;
129
127
130
- // Validate the workspace metadata that it was indeed a claimed prebuild.
128
+ // Validate via the workspace metadata that it was indeed a claimed prebuild.
131
129
const indicator = page . getByText ( "Was Prebuild" ) ;
132
130
await indicator . waitFor ( { timeout : 60_000 } ) ;
133
131
const text = indicator . locator ( "xpath=.." ) . getByText ( "Yes" ) ;
134
132
await text . waitFor ( { timeout : 30_000 } ) ;
135
133
134
+ // Validate via the workspace metadata that terraform was run again, injecting the new owner via agent environment,
135
+ // and the agent picked this up and reinitialized with a new environment.
136
+ const owner = page . getByText ( "Owner" ) ;
137
+ await owner . waitFor ( { timeout : 60_000 } ) ;
138
+ const ownerTxt = owner . locator ( "xpath=.." ) . getByText ( users . member . email ) ;
139
+ await ownerTxt . waitFor ( { timeout : 30_000 } ) ;
140
+
136
141
// Logout as unprivileged user, and login as admin.
137
142
await login ( page , users . admin ) ;
138
143
@@ -156,10 +161,14 @@ test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
156
161
expect ( currentWorkspaceNames ) . not . toEqual ( previousWorkspaceNames ) ;
157
162
158
163
// Wait for prebuilds to start.
159
- runningPrebuilds = page . getByTestId ( "build-status" ) . getByText ( "Running" ) ;
164
+ runningPrebuilds = runningPrebuildsLocator ( page ) ;
160
165
await waitForExpectedCount ( runningPrebuilds , expectedPrebuilds ) ;
161
166
} ) ;
162
167
168
+ function runningPrebuildsLocator ( page : Page ) : Locator {
169
+ return page . locator ( ".build-status" ) . getByText ( "Running" ) ;
170
+ }
171
+
163
172
function waitForExpectedCount ( prebuilds : Locator , expectedCount : number ) {
164
173
return expect
165
174
. poll (
0 commit comments