Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 29 additions & 69 deletions __tests__/e2e/session/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
set -e
set -v

REGION=${REGION:-cn-hangzhou}

echo "test session operations..."

# Deploy function first
Expand All @@ -11,16 +13,25 @@ s deploy -y

# Test create session
echo "Testing create session..."
sessionId=$(s cli fc3 session create -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --qualifier LATEST --session-ttl-in-seconds 3600 --session-idle-timeout-in-seconds 1800 -o json | jq -r '.sessionId')
sessionId=$(s cli fc3 session create --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --qualifier LATEST --session-ttl-in-seconds 3600 --session-idle-timeout-in-seconds 1800 -o json | jq -r '.sessionId')
if [ -z "$sessionId" ]; then
echo "Failed to create session"
exit 1
fi
echo "Created session: $sessionId"

# Test create session with disable-session-id-reuse
echo "Testing create session with disable-session-id-reuse..."
sessionIdDisableReuse=$(s cli fc3 session create --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --qualifier LATEST --disable-session-id-reuse -o json | jq -r '.sessionId')
if [ -z "$sessionIdDisableReuse" ]; then
echo "Failed to create session with disable-session-id-reuse"
exit 1
fi
echo "Created session with disable-session-id-reuse: $sessionIdDisableReuse"

# Test get session
echo "Testing get session..."
getSessionResult=$(s cli fc3 session get -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -o json)
getSessionResult=$(s cli fc3 session get --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -o json)
if [ -z "$getSessionResult" ]; then
echo "Failed to get session"
exit 1
Expand All @@ -29,25 +40,25 @@ echo "Get session result: $getSessionResult"

# Test update session (update sessionTTLInSeconds)
echo "Testing update session with session-ttl-in-seconds..."
updateResult=$(s cli fc3 session update -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST --session-ttl-in-seconds 7200 -o json)
updateResult=$(s cli fc3 session update --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST --session-ttl-in-seconds 7200 -o json)
if [ -z "$updateResult" ]; then
echo "Failed to update session with session-ttl-in-seconds"
exit 1
fi
echo "Update session result: $updateResult"

# Test update session (update sessionIdleTimeoutInSeconds)
echo "Testing update session with session-idle-timeout-in-seconds..."
updateResult2=$(s cli fc3 session update -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST --session-idle-timeout-in-seconds 3600 -o json)
if [ -z "$updateResult2" ]; then
echo "Failed to update session with session-idle-timeout-in-seconds"
# Test update session with disable-session-id-reuse
echo "Testing update session with disable-session-id-reuse..."
updateDisableReuseResult=$(s cli fc3 session update --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST --disable-session-id-reuse -o json)
if [ -z "$updateDisableReuseResult" ]; then
echo "Failed to update session with disable-session-id-reuse"
exit 1
fi
echo "Update session result: $updateResult2"
echo "Update session with disable-session-id-reuse result: $updateDisableReuseResult"

# Test list sessions
echo "Testing list sessions..."
listResult=$(s cli fc3 session list -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} -o json)
listResult=$(s cli fc3 session list --region $REGION --function-name fc3-session-${fc_component_function_name:-test} -o json)
if [ -z "$listResult" ]; then
echo "Failed to list sessions"
exit 1
Expand All @@ -56,77 +67,26 @@ echo "List sessions result: $listResult"

# Test list sessions with filters
echo "Testing list sessions with filters..."
listFilteredResult=$(s cli fc3 session list -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -o json)
listFilteredResult=$(s cli fc3 session list --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -o json)
if [ -z "$listFilteredResult" ]; then
echo "Failed to list sessions with filters"
exit 1
fi
echo "List sessions with filters result: $listFilteredResult"

# Test list sessions with session-status filter
echo "Testing list sessions with session-status filter..."
listStatusResult=$(s cli fc3 session list -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-status Active -o json)
# Test list sessions with session-status filter (correct case)
echo "Testing list sessions with session-status filter (Active)..."
listStatusResult=$(s cli fc3 session list --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-status Active -o json)
if [ -z "$listStatusResult" ]; then
echo "Failed to list sessions with session-status filter"
exit 1
fi
echo "List sessions with session-status filter result: $listStatusResult"

# Test list sessions with limit parameter
echo "Testing list sessions with limit parameter..."
listLimitResult=$(s cli fc3 session list -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --limit 5 -o json)
if [ -z "$listLimitResult" ]; then
echo "Failed to list sessions with limit parameter"
exit 1
fi
echo "List sessions with limit parameter result: $listLimitResult"

# Test remove session
echo "Testing remove session..."
removeResult=$(s cli fc3 session remove -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -y -o json)
echo "Remove session result: $removeResult"

# Verify session is removed by trying to get it (should fail)
echo "Verifying session is removed..."
getRemovedSessionResult=$(s cli fc3 session get -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -o json 2>&1 || true)
if [[ $getRemovedSessionResult == *"not found"* ]] || [[ $getRemovedSessionResult == *"not exist"* ]]; then
echo "Session successfully removed"
else
echo "Session removal verification failed: $getRemovedSessionResult"
# Don't exit here as this might be a timing issue
fi

# Test create session without optional parameters (should use defaults)
echo "Testing create session with default parameters..."
sessionId2=$(s cli fc3 session create -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --qualifier LATEST -o json | jq -r '.sessionId')
if [ -z "$sessionId2" ]; then
echo "Failed to create session with default parameters"
exit 1
fi
echo "Created session with defaults: $sessionId2"

# Test create session with only sessionTTLInSeconds
echo "Testing create session with only session-ttl-in-seconds..."
sessionId3=$(s cli fc3 session create -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --qualifier LATEST --session-ttl-in-seconds 1800 -o json | jq -r '.sessionId')
if [ -z "$sessionId3" ]; then
echo "Failed to create session with only session-ttl-in-seconds"
exit 1
fi
echo "Created session with only session-ttl-in-seconds: $sessionId3"

# Test create session with only sessionIdleTimeoutInSeconds
echo "Testing create session with only session-idle-timeout-in-seconds..."
sessionId4=$(s cli fc3 session create -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --qualifier LATEST --session-idle-timeout-in-seconds 900 -o json | jq -r '.sessionId')
if [ -z "$sessionId4" ]; then
echo "Failed to create session with only session-idle-timeout-in-seconds"
exit 1
fi
echo "Created session with only session-idle-timeout-in-seconds: $sessionId4"

# Clean up additional sessions
s cli fc3 session remove -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId2 --qualifier LATEST -y || true
s cli fc3 session remove -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId3 --qualifier LATEST -y || true
s cli fc3 session remove -a quanxi --region cn-hangzhou --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId4 --qualifier LATEST -y || true
# Test remove sessions
echo "Testing remove sessions..."
s cli fc3 session remove --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionId --qualifier LATEST -y || true
s cli fc3 session remove --region $REGION --function-name fc3-session-${fc_component_function_name:-test} --session-id $sessionIdDisableReuse --qualifier LATEST -y || true

# Clean up function
echo "Cleaning up..."
Expand Down
4 changes: 2 additions & 2 deletions __tests__/e2e/session/s.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
edition: 3.0.0
name: session-test
access: quanxi
access: default

vars:
region: ${env('REGION', 'cn-hongkong')}
region: ${env('REGION', 'cn-hangzhou')}

resources:
sessionTest:
Expand Down
193 changes: 193 additions & 0 deletions __tests__/ut/commands/session_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,153 @@ describe('Session', () => {
},
});
});

it('should create session with disableSessionIdReuse when provided', async () => {
const mockResult = {
sessionId: 'session-123',
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
disableSessionIdReuse: true,
};

mockFcSdk.createFunctionSession = jest.fn().mockResolvedValue(mockResult);
mockInputs.args = [
'create',
'--qualifier',
'LATEST',
'--session-ttl-in-seconds',
'3600',
'--session-idle-timeout-in-seconds',
'1800',
'--disable-session-id-reuse',
];
session = new Session(mockInputs);

const result = await session.create();
expect(result).toEqual(mockResult);
expect(mockFcSdk.createFunctionSession).toHaveBeenCalledWith('test-function', {
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
disableSessionIdReuse: true,
});
});

it('should create session with custom sessionId when provided', async () => {
const mockResult = {
sessionId: 'custom-session-id',
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
};

mockFcSdk.createFunctionSession = jest.fn().mockResolvedValue(mockResult);
mockInputs.args = [
'create',
'--qualifier',
'LATEST',
'--session-ttl-in-seconds',
'3600',
'--session-idle-timeout-in-seconds',
'1800',
'--session-id',
'custom-session-id',
];
session = new Session(mockInputs);

const result = await session.create();
expect(result).toEqual(mockResult);
expect(mockFcSdk.createFunctionSession).toHaveBeenCalledWith('test-function', {
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
sessionId: 'custom-session-id',
});
});

it('should create session with ossMountConfig when provided', async () => {
const mockResult = {
sessionId: 'session-123',
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
};

mockFcSdk.createFunctionSession = jest.fn().mockResolvedValue(mockResult);
mockInputs.args = [
'create',
'--qualifier',
'LATEST',
'--session-ttl-in-seconds',
'3600',
'--session-idle-timeout-in-seconds',
'1800',
'--oss-mount-config',
'{"mountPoints":[{"bucketName":"test-bucket","bucketPath":"cn-hangzhou","mountDir":"/mnt/oss","readOnly":false}]}',
];
session = new Session(mockInputs);

const result = await session.create();
expect(result).toEqual(mockResult);
expect(mockFcSdk.createFunctionSession).toHaveBeenCalledWith('test-function', {
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
ossMountConfig: {
mountPoints: [
{
bucketName: 'test-bucket',
bucketPath: 'cn-hangzhou',
mountDir: '/mnt/oss',
readOnly: false,
},
],
},
});
});
Comment on lines +264 to +294
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Misleading bucketPath value in ossMountConfig test fixture.

bucketPath is a path inside the OSS bucket (e.g. "/" or "/my-dir"), not a region. Passing "cn-hangzhou" as bucketPath is confusing test data that could be copied by users reading tests as a reference. Also missing endpoint, which is the real OSS-region-bearing field in OSSMountPoint.

♻️ Suggested fix
-        '--oss-mount-config',
-        '{"mountPoints":[{"bucketName":"test-bucket","bucketPath":"cn-hangzhou","mountDir":"/mnt/oss","readOnly":false}]}',
+        '--oss-mount-config',
+        '{"mountPoints":[{"bucketName":"test-bucket","bucketPath":"/","endpoint":"http://oss-cn-hangzhou.aliyuncs.com","mountDir":"/mnt/oss","readOnly":false}]}',

And update the expected assertion object accordingly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/ut/commands/session_test.ts` around lines 264 - 294, The test uses
a misleading OSS mount fixture: change the OSSMountPoint in the mockInputs.args
for Session (used by Session.create()) so bucketPath is a real bucket-internal
path (e.g. "/" or "/my-dir") instead of "cn-hangzhou", and add the endpoint
field (e.g. "oss-cn-hangzhou.aliyuncs.com"); then update the expected assertion
passed to mockFcSdk.createFunctionSession to include the corrected
ossMountConfig with the new bucketPath and endpoint fields so the test reflects
real OSS semantics.


it('should create session with polarFsConfig when provided', async () => {
const mockResult = {
sessionId: 'session-123',
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
};

mockFcSdk.createFunctionSession = jest.fn().mockResolvedValue(mockResult);
mockInputs.args = [
'create',
'--qualifier',
'LATEST',
'--session-ttl-in-seconds',
'3600',
'--session-idle-timeout-in-seconds',
'1800',
'--polar-fs-config',
'{"userId":1000,"groupId":1000,"mountPoints":[{"polarDbClusterId":"pc-test","instanceId":"pfs-test","mountDir":"/mnt/polar"}]}',
];
session = new Session(mockInputs);

const result = await session.create();
expect(result).toEqual(mockResult);
expect(mockFcSdk.createFunctionSession).toHaveBeenCalledWith('test-function', {
qualifier: 'LATEST',
sessionTTLInSeconds: 3600,
sessionIdleTimeoutInSeconds: 1800,
polarFsConfig: {
userId: 1000,
groupId: 1000,
mountPoints: [
{
polarDbClusterId: 'pc-test',
instanceId: 'pfs-test',
mountDir: '/mnt/polar',
},
],
},
});
});
Comment on lines +296 to +336
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

polarDbClusterId is not a valid PolarFsMountConfig field; remoteDir is missing.

The SDK PolarFsMountConfig accepts instanceId, mountDir, remoteDir (see the mapping in createFunctionSession at src/resources/fc/index.ts lines 1009–1015). polarDbClusterId is neither in the SDK nor consumed by the code — including it in this test payload is misleading and inconsistent with the earlier doc fix in commit 8daee0f. Also remoteDir is required in typical PolarFS usage and should be represented here.

♻️ Suggested fix
-        '--polar-fs-config',
-        '{"userId":1000,"groupId":1000,"mountPoints":[{"polarDbClusterId":"pc-test","instanceId":"pfs-test","mountDir":"/mnt/polar"}]}',
+        '--polar-fs-config',
+        '{"userId":1000,"groupId":1000,"mountPoints":[{"instanceId":"pfs-test","mountDir":"/mnt/polar","remoteDir":"/"}]}',

And update the expected assertion object to drop polarDbClusterId and include remoteDir: "/".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/ut/commands/session_test.ts` around lines 296 - 336, The test is
using an invalid PolarFsMountConfig field `polarDbClusterId` and omitting
required `remoteDir`; update the test payload and expectation in the 'should
create session with polarFsConfig when provided' spec so the mock input JSON for
--polar-fs-config uses mountPoints objects with instanceId, mountDir, and
remoteDir (e.g. remoteDir: "/") instead of polarDbClusterId, and adjust the
expected argument passed to mockFcSdk.createFunctionSession (the call asserted
in the test) to match this shape; locate references in this test to Session and
mockFcSdk.createFunctionSession to change both the input string and the expected
polarFsConfig object.

});

describe('get', () => {
Expand Down Expand Up @@ -267,6 +414,18 @@ describe('Session', () => {
};

mockFcSdk.updateFunctionSession = jest.fn().mockResolvedValue(mockResult);
mockInputs.args = [
'update',
'--session-id',
'session-123',
'--qualifier',
'LATEST',
'--session-ttl-in-seconds',
'7200',
'--session-idle-timeout-in-seconds',
'3600',
];
session = new Session(mockInputs);

const result = await session.update();
expect(result).toEqual(mockResult);
Expand Down Expand Up @@ -321,6 +480,40 @@ describe('Session', () => {
'timeout must be a number between 0 and 21600',
);
});

it('should update session with disableSessionIdReuse when provided', async () => {
const mockResult = {
sessionId: 'session-123',
qualifier: 'LATEST',
sessionTTLInSeconds: 7200,
sessionIdleTimeoutInSeconds: 3600,
disableSessionIdReuse: true,
};

mockFcSdk.updateFunctionSession = jest.fn().mockResolvedValue(mockResult);
mockInputs.args = [
'update',
'--session-id',
'session-123',
'--qualifier',
'LATEST',
'--session-ttl-in-seconds',
'7200',
'--session-idle-timeout-in-seconds',
'3600',
'--disable-session-id-reuse',
];
session = new Session(mockInputs);

const result = await session.update();
expect(result).toEqual(mockResult);
expect(mockFcSdk.updateFunctionSession).toHaveBeenCalledWith('test-function', 'session-123', {
qualifier: 'LATEST',
sessionTTLInSeconds: 7200,
sessionIdleTimeoutInSeconds: 3600,
disableSessionIdReuse: true,
});
});
});

describe('list', () => {
Expand Down
Loading
Loading