Skip to content

Commit a9cb979

Browse files
DavertMikDavertMikclaude
authored
fix: auth plugin loginAs injection broken in 4.x (#5502)
* fix: return plugin-injected functions directly from container instead of wrapping in non-callable Proxy The 4.x ESM migration changed Container.support(name) to always go through the proxy, which wraps values in lazyLoad() — a Proxy designed for page objects (property access), not callable functions. This broke the auth plugin's loginAs/login injection since the returned Proxy has no apply trap. Also fixes missing-key detection in inject.js (was never firing because lazyLoad always returns a truthy Proxy). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * revert: inject.js missing-key check change that broke I injection The `!(key in objects)` check used the proxy's `has` trap which doesn't include keys added directly to container.support (like the Actor `I` from createActor). Reverting to the original `!objects[key]` check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: DavertMik <davert@testomat.io> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 86ea01e commit a9cb979

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/container.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ class Container {
150150
if (!name) {
151151
return container.proxySupport
152152
}
153-
// Always return the proxy to ensure MetaStep creation works
153+
if (typeof container.support[name] === 'function') {
154+
return container.support[name]
155+
}
154156
return container.proxySupport[name]
155157
}
156158

@@ -600,6 +602,8 @@ function createSupportObjects(config) {
600602
let value
601603
if (container.sharedKeys.has(prop) && prop in container.support) {
602604
value = container.support[prop]
605+
} else if (prop in container.support && typeof container.support[prop] === 'function') {
606+
value = container.support[prop]
603607
} else {
604608
value = lazyLoad(prop)
605609
}
@@ -614,6 +618,9 @@ function createSupportObjects(config) {
614618
if (container.sharedKeys.has(key) && key in container.support) {
615619
return container.support[key]
616620
}
621+
if (key in container.support && typeof container.support[key] === 'function') {
622+
return container.support[key]
623+
}
617624
return lazyLoad(key)
618625
},
619626
},

test/unit/container_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ describe('Container', () => {
287287
expect(container.support('userPage')).is.ok
288288
expect(container.support('userPage').login).is.eql('#login')
289289
})
290+
291+
it('should be able to add and retrieve a function as a support object', async () => {
292+
await container.create({})
293+
const loginFunction = async name => `logged in as ${name}`
294+
container.append({ support: { loginAs: loginFunction } })
295+
expect(container.support('I')).is.ok
296+
const loginAs = container.support('loginAs')
297+
expect(loginAs).to.be.a('function')
298+
const result = await loginAs('admin')
299+
expect(result).to.eql('logged in as admin')
300+
})
290301
})
291302

292303
describe('TypeScript support', () => {

0 commit comments

Comments
 (0)