Skip to content

Commit f8feed7

Browse files
robingenzclaude
andauthored
feat(release): warn about a progression step that is too small before the confirmation (#148)
`release create` sends the progression to the audience preview. The preview then warns when a step adds fewer devices than the applied updates it waits for. The preview's warnings print before the confirmation, no longer after the create, so a person reads them while the answer can still be no. A progression the API refuses now fails at the preview, before the confirmation and before any upload. A dry run with such a progression exits 1. `@hotcodepush/node` moves to 0.2.2, which carries the two query fields. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent acae689 commit f8feed7

6 files changed

Lines changed: 36 additions & 18 deletions

File tree

‎package-lock.json‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"dependencies": {
6767
"@clack/core": "1.5.1",
6868
"@clack/prompts": "1.8.1",
69-
"@hotcodepush/node": "0.2.1",
69+
"@hotcodepush/node": "0.2.2",
7070
"@hotcodepush/protocol": "0.1.0",
7171
"@napi-rs/keyring": "2.1.0",
7272
"better-auth": "1.7.16",

‎src/commands/audience/get.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { locateProjectConfig } from '../../utils/project-config.js';
1818

1919
export default defineCommand({
2020
description:
21-
"Preview the devices a release's conditions would reach in a channel, before it exists, the project's fingerprint among them. This is what release create --dry-run prints.",
21+
"Preview the devices a release's conditions would reach in a channel, before it exists, the project's fingerprint among them. It counts the same devices as release create --dry-run.",
2222
examples: [
2323
'hotcodepush audience get --binary-version ">=2.3.0" --rollout-percent 10',
2424
'hotcodepush audience get --channel production --attribute tier=beta --device 6b1e9d37-2f5c-4a80-9c46-d8e3a1f7b259 --json',
@@ -43,6 +43,7 @@ export default defineCommand({
4343
const audience = await hotCodePush.apps.channels.audience.get({
4444
...buildAudienceQuery(options, {
4545
fingerprint: await readProjectFingerprint(options.config),
46+
progression: null,
4647
rolloutPercent,
4748
}),
4849
appId: channel.appId,

‎src/commands/release/create.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ describe('release create', () => {
440440
respondWithCreatedRelease({ release: PROGRESSING_RELEASE });
441441
});
442442

443-
it("should start at the default schedule's first percentage once confirmed, stating the schedule", async () => {
443+
it('should preview the default schedule and start at its first percentage once confirmed, stating the schedule', async () => {
444444
stubInteractiveTerminal();
445445
vi.mocked(confirm).mockResolvedValue(true);
446446

@@ -459,8 +459,15 @@ describe('release create', () => {
459459
message:
460460
'This releases bundle #17 · 1.4.2 at 10 percent, progressing through 10, 50, 100 percent, each step at least 3600 seconds and 50 applied updates: reaches 100 of 120 active devices in staging, about 100 at a 10 percent rollout. Continue?',
461461
});
462-
expect(readAudienceUrls()[0]?.searchParams.get('rolloutPercent')).toBe(
462+
const audienceParams = readAudienceUrls()[0]?.searchParams;
463+
expect(audienceParams?.get('rolloutPercent')).toBe('10');
464+
expect(audienceParams?.getAll('progressionRolloutPercent')).toEqual([
463465
'10',
466+
'50',
467+
'100',
468+
]);
469+
expect(audienceParams?.get('progressionStepMinimumUpdateCount')).toBe(
470+
'50',
464471
);
465472
const [createRequest] = readCreateRequests();
466473
expect(await createRequest?.json()).toMatchObject({
@@ -715,12 +722,14 @@ describe('release create', () => {
715722
});
716723
});
717724

718-
it("should print the audience preview's warnings once the release is created", async () => {
725+
it("should print the audience preview's warnings before it asks, when the answer is no too", async () => {
719726
const fingerprintUnknownWarning: Audience['warnings'][number] = {
720727
code: 'fingerprint_unknown',
721728
details: { fingerprint: CAPACITOR_FINGERPRINT },
722729
message: 'No binary of the app carries this fingerprint.',
723730
};
731+
stubInteractiveTerminal();
732+
vi.mocked(confirm).mockResolvedValue(false);
724733
stubWebBuildUpload();
725734
respondWithStagingChannel({
726735
...STAGING_AUDIENCE,
@@ -729,22 +738,21 @@ describe('release create', () => {
729738
UNSUPPORTED_CONDITION_SHARE_WARNING,
730739
],
731740
});
732-
respondWithCreatedRelease();
733741

734742
await releaseCreateCommand.action(
735743
{
736744
app: DEMO_APP.id,
737745
attribute: ['tier=beta'],
738746
channel: STAGING_CHANNEL.id,
739747
path: 'dist',
740-
yes: true,
741748
},
742749
undefined,
743750
);
744751

745752
expect(harness.readDiagnostics()).toBe(
746753
`${fingerprintUnknownWarning.message}\n${UNSUPPORTED_CONDITION_SHARE_WARNING.message}\n`,
747754
);
755+
expect(readCreateRequests()).toEqual([]);
748756
});
749757

750758
it('should stop with `confirmation_required` stating the audience at a partial rollout, with the mandatory flag, when nobody can confirm', async () => {

‎src/commands/release/create.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ async function createRelease(
244244
}
245245
return;
246246
}
247+
printWarnings(audience.warnings);
247248
if (!(await confirmConsequence(plan.consequence, options))) {
248249
return;
249250
}
@@ -252,7 +253,6 @@ async function createRelease(
252253
channel,
253254
releaseBody: buildReleaseBody(bundle, { options, plan }),
254255
});
255-
printWarnings(audience.warnings);
256256
if (options.json) {
257257
printJson(liveRelease);
258258
} else {
@@ -325,19 +325,19 @@ async function fetchBundleSource(
325325
});
326326
}
327327

328-
// The audience preview checks the conditions before anything is uploaded.
328+
// The audience preview checks the conditions and the schedule before anything is uploaded.
329329
async function fetchChannelAudience(
330330
hotCodePush: HotCodePush,
331331
{
332332
appId,
333333
fingerprint,
334334
options,
335-
rolloutPercent,
335+
rollout,
336336
}: {
337337
appId: string;
338338
fingerprint: string | null;
339339
options: ReleaseCreateOptions;
340-
rolloutPercent: number;
340+
rollout: ReleaseRollout;
341341
},
342342
): Promise<ChannelAudience> {
343343
const channel = await hotCodePush.apps.channels.get({
@@ -351,7 +351,8 @@ async function fetchChannelAudience(
351351
const audience = await fetchAudience(hotCodePush, {
352352
audienceQuery: buildAudienceQuery(options, {
353353
fingerprint,
354-
rolloutPercent,
354+
progression: rollout.progression,
355+
rolloutPercent: rollout.rolloutPercent,
355356
}),
356357
channel,
357358
});
@@ -377,7 +378,7 @@ async function fetchReleasePlan(
377378
appId: resolveSourceAppId(bundleSource),
378379
fingerprint,
379380
options,
380-
rolloutPercent: rollout.rolloutPercent,
381+
rollout,
381382
});
382383
return {
383384
bundleSource,

‎src/resources/releases/conditions.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { z } from 'zod';
1010
import { InvalidParameterError } from '../../utils/errors.js';
1111
import { resolveNameValuePairs } from '../../utils/name-value-pairs.js';
12+
import type { Progression } from './progression.js';
1213

1314
export interface ConditionOptions {
1415
attribute?: string[];
@@ -49,8 +50,13 @@ export function buildAudienceQuery(
4950
options: ConditionOptions,
5051
{
5152
fingerprint,
53+
progression,
5254
rolloutPercent,
53-
}: { fingerprint: string | null; rolloutPercent: number },
55+
}: {
56+
fingerprint: string | null;
57+
progression: Progression | null;
58+
rolloutPercent: number;
59+
},
5460
): AudienceQuery {
5561
return {
5662
attribute: resolveAttributePairs(options.attribute).map(
@@ -60,6 +66,8 @@ export function buildAudienceQuery(
6066
device: options.device ?? [],
6167
fingerprint: resolveList(fingerprint ?? undefined),
6268
os: resolveList(options.osVersion),
69+
progressionRolloutPercent: progression?.rolloutPercents,
70+
progressionStepMinimumUpdateCount: progression?.stepMinimumUpdateCount,
6371
rolloutPercent,
6472
};
6573
}

0 commit comments

Comments
 (0)