Skip to content

Commit 9f2756b

Browse files
committed
Merge remote-tracking branch 'origin/staging' into feat/permission-aware-knowledge
2 parents dfeaf87 + d218534 commit 9f2756b

5 files changed

Lines changed: 81 additions & 11 deletions

File tree

.github/workflows/desktop-release.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,47 @@ jobs:
187187
printf '%s' "$APPLE_API_KEY_P8" > "$RUNNER_TEMP/appstoreconnect/AuthKey.p8"
188188
chmod 600 "$RUNNER_TEMP/appstoreconnect/AuthKey.p8"
189189
190-
- name: Package, sign, and notarize
190+
- name: Import Apple signing certificate
191191
if: ${{ inputs.sign }}
192-
working-directory: apps/desktop
193192
env:
194193
CSC_LINK: ${{ secrets.CSC_LINK }}
195194
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
195+
run: |
196+
CERTIFICATE_PATH="$RUNNER_TEMP/desktop-signing.p12"
197+
KEYCHAIN_PATH="$RUNNER_TEMP/desktop-signing.keychain-db"
198+
KEYCHAIN_PASSWORD="$(openssl rand -base64 32)"
199+
200+
printf '%s' "$CSC_LINK" | base64 --decode > "$CERTIFICATE_PATH"
201+
chmod 600 "$CERTIFICATE_PATH"
202+
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
203+
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
204+
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
205+
security import "$CERTIFICATE_PATH" -k "$KEYCHAIN_PATH" -P "$CSC_KEY_PASSWORD" \
206+
-T /usr/bin/codesign -T /usr/bin/productbuild
207+
security set-key-partition-list -S apple-tool:,apple: -s \
208+
-k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" > /dev/null
209+
210+
EXISTING_KEYCHAINS=("$KEYCHAIN_PATH")
211+
while IFS= read -r EXISTING_KEYCHAIN; do
212+
EXISTING_KEYCHAIN="${EXISTING_KEYCHAIN#*\"}"
213+
EXISTING_KEYCHAIN="${EXISTING_KEYCHAIN%\"}"
214+
if [ "$EXISTING_KEYCHAIN" != "$KEYCHAIN_PATH" ]; then
215+
EXISTING_KEYCHAINS+=("$EXISTING_KEYCHAIN")
216+
fi
217+
done < <(security list-keychains -d user)
218+
security list-keychains -d user -s "${EXISTING_KEYCHAINS[@]}"
219+
220+
SIGNING_IDENTITIES="$(security find-identity -v -p codesigning "$KEYCHAIN_PATH")"
221+
if ! grep -q 'Developer ID Application' <<< "$SIGNING_IDENTITIES"; then
222+
echo '::error::The signing certificate does not contain a valid Developer ID Application identity.'
223+
exit 1
224+
fi
225+
226+
- name: Package, sign, and notarize
227+
if: ${{ inputs.sign }}
228+
working-directory: apps/desktop
229+
env:
230+
CSC_KEYCHAIN: ${{ runner.temp }}/desktop-signing.keychain-db
196231
# Absolute path — @electron/notarize reads this via Node fs, which
197232
# does not expand a leading '~'.
198233
APPLE_API_KEY: ${{ runner.temp }}/appstoreconnect/AuthKey.p8
@@ -205,6 +240,13 @@ jobs:
205240
bunx electron-builder --mac --publish never
206241
-c.productName="$PRODUCT_NAME" -c.appId="$APP_ID"
207242
243+
- name: Remove Apple signing credentials
244+
if: ${{ always() && inputs.sign }}
245+
run: |
246+
security delete-keychain "$RUNNER_TEMP/desktop-signing.keychain-db" || true
247+
rm -f "$RUNNER_TEMP/desktop-signing.p12"
248+
rm -f "$RUNNER_TEMP/appstoreconnect/AuthKey.p8"
249+
208250
# Unsigned artifact-only path: no Developer ID or notarization. The bundle
209251
# is ad-hoc signed with Hardened Runtime off for local workflow testing and
210252
# must never be published.

apps/sim/ee/organization-usage/constants.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ComboboxOption } from '@sim/emcn'
22
import {
3+
ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT,
4+
ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT,
35
USAGE_WINDOW_PRESETS,
46
type UsageBreakdownDimension,
57
type UsageWindowPreset,
@@ -78,13 +80,12 @@ export const USAGE_TAB_EMPTY_COPY: Record<UsageBreakdownDimension, string> = {
7880
/**
7981
* Rows per breakdown before and after the `Other` row is expanded.
8082
*
81-
* The collapsed count keeps a tab to one screen; the expanded one is the contract's
82-
* own ceiling (`usageLimitSchema(50, 10)`), so asking for more would be refused. A
83-
* dimension with more than {@link EXPANDED_ROW_COUNT} distinct rows still shows an
84-
* `Other` row after expanding, which is the honest result rather than a bug.
83+
* Each tab shows the contract default immediately, then can request the contract
84+
* ceiling by expanding `Other`. A dimension with more than
85+
* {@link EXPANDED_ROW_COUNT} distinct rows still shows a remainder after expanding.
8586
*/
86-
export const COLLAPSED_ROW_COUNT = 10
87-
export const EXPANDED_ROW_COUNT = 50
87+
export const COLLAPSED_ROW_COUNT = ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT
88+
export const EXPANDED_ROW_COUNT = ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT
8889

8990
export const DEFAULT_USAGE_PRESET = 'current-period' as const
9091
export const DEFAULT_USAGE_TAB = USAGE_OVERVIEW_TAB

apps/sim/hooks/queries/organization-usage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getOrganizationUsageBreakdownContract,
77
getOrganizationUsageSummaryContract,
88
listOrganizationUsageEventsContract,
9+
ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT,
910
type OrganizationUsageBreakdown,
1011
type OrganizationUsageEventPage,
1112
type OrganizationUsageSummary,
@@ -96,7 +97,7 @@ export function useOrganizationUsageBreakdown(
9697
dimension: UsageBreakdownDimension,
9798
options: UseBreakdownOptions = {}
9899
) {
99-
const limit = options.limit ?? 10
100+
const limit = options.limit ?? ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT
100101
const { workspaceId } = options
101102
const queryKey = organizationUsageKeys.breakdown(
102103
organizationId ?? '',

apps/sim/lib/api/contracts/organization-usage.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* @vitest-environment node
33
*/
44
import { describe, expect, it } from 'vitest'
5-
import { organizationUsageEventsQuerySchema } from '@/lib/api/contracts/organization-usage'
5+
import {
6+
organizationUsageBreakdownQuerySchema,
7+
organizationUsageEventsQuerySchema,
8+
} from '@/lib/api/contracts/organization-usage'
69

710
/** The shared window fields every usage contract extends, exercised through one of them. */
811
function parseWindow(input: Record<string, unknown>) {
@@ -68,3 +71,20 @@ describe('organization usage window contract', () => {
6871
expect(parseWindow({ timezone: 'Mars/Olympus_Mons' }).success).toBe(false)
6972
})
7073
})
74+
75+
describe('organization usage breakdown contract', () => {
76+
const baseQuery = { dimension: 'workspace' as const }
77+
78+
it('defaults to 50 rows', () => {
79+
expect(organizationUsageBreakdownQuerySchema.parse(baseQuery).limit).toBe(50)
80+
})
81+
82+
it('allows expansion to 100 rows and refuses larger requests', () => {
83+
expect(
84+
organizationUsageBreakdownQuerySchema.safeParse({ ...baseQuery, limit: 100 }).success
85+
).toBe(true)
86+
expect(
87+
organizationUsageBreakdownQuerySchema.safeParse({ ...baseQuery, limit: 101 }).success
88+
).toBe(false)
89+
})
90+
})

apps/sim/lib/api/contracts/organization-usage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export type UsageBreakdownDimension = z.output<typeof usageBreakdownDimensionSch
4040
*/
4141
export const MAX_CUSTOM_RANGE_DAYS = 92
4242

43+
export const ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT = 50
44+
export const ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT = 100
45+
4346
/**
4447
* A bare `YYYY-MM-DD` calendar date, and nothing else.
4548
*
@@ -144,7 +147,10 @@ export type OrganizationUsageSummaryQuery = z.input<typeof organizationUsageSumm
144147
export const organizationUsageBreakdownQuerySchema = organizationUsageWindowQuerySchema.extend({
145148
...usageWorkspaceScopeShape,
146149
dimension: usageBreakdownDimensionSchema,
147-
limit: usageLimitSchema(50, 10),
150+
limit: usageLimitSchema(
151+
ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT,
152+
ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT
153+
),
148154
})
149155
export type OrganizationUsageBreakdownQuery = z.input<typeof organizationUsageBreakdownQuerySchema>
150156

0 commit comments

Comments
 (0)