55 */
66import * as assert from 'assert' ;
77import {
8+ CLONE_PROFILES ,
89 CLONE_IN_PROGRESS_STATES ,
910 TRANSITIONAL_STATES ,
1011 computeSandboxDisplay ,
1112 getActiveCloneSourceIds ,
13+ getAllowedCloneTargetProfiles ,
14+ getExplicitCloneTargetProfiles ,
1215 getRealmInstanceId ,
16+ getSandboxSourceProfile ,
17+ isCloneProfileDowngrade ,
18+ normalizeCloneProfile ,
1319 type SandboxLike ,
1420} from '../sandbox-tree/sandbox-clone-helpers.js' ;
1521
@@ -18,6 +24,57 @@ function sandbox(partial: Partial<SandboxLike> & {id: string}): SandboxLike {
1824}
1925
2026suite ( 'sandbox-clone-helpers' , ( ) => {
27+ suite ( 'clone profile helpers' , ( ) => {
28+ test ( 'normalizeCloneProfile handles case and whitespace' , ( ) => {
29+ assert . strictEqual ( normalizeCloneProfile ( ' LARGE ' ) , 'large' ) ;
30+ assert . strictEqual ( normalizeCloneProfile ( 'xlarge' ) , 'xlarge' ) ;
31+ assert . strictEqual ( normalizeCloneProfile ( undefined ) , undefined ) ;
32+ assert . strictEqual ( normalizeCloneProfile ( '' ) , undefined ) ;
33+ assert . strictEqual ( normalizeCloneProfile ( 'tiny' ) , undefined ) ;
34+ } ) ;
35+
36+ test ( 'getAllowedCloneTargetProfiles returns all profiles when source profile is unknown' , ( ) => {
37+ assert . deepStrictEqual ( getAllowedCloneTargetProfiles ( undefined ) , [ ...CLONE_PROFILES ] ) ;
38+ assert . deepStrictEqual ( getAllowedCloneTargetProfiles ( 'tiny' ) , [ ...CLONE_PROFILES ] ) ;
39+ } ) ;
40+
41+ test ( 'getAllowedCloneTargetProfiles blocks downgrades for large source' , ( ) => {
42+ assert . deepStrictEqual ( getAllowedCloneTargetProfiles ( 'large' ) , [ 'large' , 'xlarge' , 'xxlarge' ] ) ;
43+ } ) ;
44+
45+ test ( 'getSandboxSourceProfile falls back to resourceProfile when profile is missing' , ( ) => {
46+ assert . strictEqual ( getSandboxSourceProfile ( { resourceProfile : 'large' } ) , 'large' ) ;
47+ } ) ;
48+
49+ test ( 'getSandboxSourceProfile prefers profile when both are present' , ( ) => {
50+ assert . strictEqual ( getSandboxSourceProfile ( { profile : 'xlarge' , resourceProfile : 'large' } ) , 'xlarge' ) ;
51+ } ) ;
52+
53+ test ( 'getAllowedCloneTargetProfiles allows only xxlarge for xxlarge source' , ( ) => {
54+ assert . deepStrictEqual ( getAllowedCloneTargetProfiles ( 'xxlarge' ) , [ 'xxlarge' ] ) ;
55+ } ) ;
56+
57+ test ( 'getExplicitCloneTargetProfiles excludes source profile for large source' , ( ) => {
58+ assert . deepStrictEqual ( getExplicitCloneTargetProfiles ( 'large' ) , [ 'xlarge' , 'xxlarge' ] ) ;
59+ } ) ;
60+
61+ test ( 'getExplicitCloneTargetProfiles returns empty list for xxlarge source' , ( ) => {
62+ assert . deepStrictEqual ( getExplicitCloneTargetProfiles ( 'xxlarge' ) , [ ] ) ;
63+ } ) ;
64+
65+ test ( 'getExplicitCloneTargetProfiles keeps all options when source profile is unknown' , ( ) => {
66+ assert . deepStrictEqual ( getExplicitCloneTargetProfiles ( undefined ) , [ ...CLONE_PROFILES ] ) ;
67+ } ) ;
68+
69+ test ( 'isCloneProfileDowngrade detects downgrade and allows same/upgrade' , ( ) => {
70+ assert . strictEqual ( isCloneProfileDowngrade ( 'large' , 'medium' ) , true ) ;
71+ assert . strictEqual ( isCloneProfileDowngrade ( 'large' , 'large' ) , false ) ;
72+ assert . strictEqual ( isCloneProfileDowngrade ( 'large' , 'xlarge' ) , false ) ;
73+ assert . strictEqual ( isCloneProfileDowngrade ( 'large' , undefined ) , false ) ;
74+ assert . strictEqual ( isCloneProfileDowngrade ( undefined , 'medium' ) , false ) ;
75+ } ) ;
76+ } ) ;
77+
2178 suite ( 'getRealmInstanceId' , ( ) => {
2279 test ( 'joins realm and instance' , ( ) => {
2380 assert . strictEqual ( getRealmInstanceId ( sandbox ( { id : 'x' , realm : 'zzzz' , instance : '004' } ) ) , 'zzzz-004' ) ;
0 commit comments