Skip to content
Merged
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
48 changes: 48 additions & 0 deletions .github/workflows/crux-file-size-ratchet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: crux file-size ratchet

# src/crux is published to hivecommons/crux by the crux-sync workflow, and crux
# main enforces a Go file-size ratchet that hive CI never ran, so a PR growing a
# grandfathered src/crux file was green here and broke crux main on the next
# sync (#15331). crux stays the source of truth: its script and baseline are
# fetched from crux main at run time, never vendored into hive.
on:
pull_request:
paths:
- 'src/crux/**'
- '.github/workflows/crux-file-size-ratchet.yml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
crux-file-size-ratchet:
name: crux-file-size-ratchet
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
sparse-checkout: src/crux

- name: Check out the ratchet script and baseline from crux main
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: hivecommons/crux
ref: main
path: crux-ratchet
persist-credentials: false
fetch-depth: 1
sparse-checkout: |
.github/scripts/check-file-size-ratchet.sh
.github/go-file-size-ratchet.txt
sparse-checkout-cone-mode: false

- name: Check non-test Go file sizes in src/crux against crux's baseline
working-directory: src/crux
run: bash "$GITHUB_WORKSPACE/crux-ratchet/.github/scripts/check-file-size-ratchet.sh" "$GITHUB_WORKSPACE/crux-ratchet/.github/go-file-size-ratchet.txt"
1 change: 1 addition & 0 deletions changelog.d/added-15331-crux-file-size-ratchet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Hive PRs that touch `src/crux/**` now run crux's Go file-size ratchet (the `crux-file-size-ratchet` check), using the script and baseline fetched from crux `main` at run time. A PR that grows a grandfathered `src/crux` file past its baseline now fails in hive with crux's own `::error::` annotation instead of breaking crux `main` on the next sync. (#15331)
42 changes: 0 additions & 42 deletions src/crux/agent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,48 +799,6 @@ func (m *Manager) GetACMMLevel() int {
return m.project.ACMMLevel
}

type ManagerOption func(*managerOptions)

type managerOptions struct {
uidMapPath string
uidMapPathSet bool
sharedPool SharedSessionPool
}

// WithUIDMapPath points a manager at a specific persisted UID map. Production
// callers keep the default UIDMapPath; tests can inject a hermetic path.
func WithUIDMapPath(path string) ManagerOption {
return func(opts *managerOptions) {
opts.uidMapPath = path
opts.uidMapPathSet = true
}
}

// WithSharedSessionPool opts a manager into a Hub-coordinated live CLI slot.
// Every Hive retains separate sessions and tenant data; the lease only limits
// how many CLI sessions across the participating Hives remain live.
func WithSharedSessionPool(pool SharedSessionPool) ManagerOption {
return func(opts *managerOptions) { opts.sharedPool = pool }
}

func (m *Manager) effectiveUIDMapPath() string {
if m.uidMapPath != "" {
return m.uidMapPath
}
return UIDMapPath
}

func (m *Manager) saveUIDMap() {
if m.uidMap == nil {
return
}
path := m.effectiveUIDMapPath()
_ = m.uidMap.Save(path)
if path == PersistedUIDMapPath && UIDMapPath != "" && UIDMapPath != path {
_ = m.uidMap.Save(UIDMapPath)
}
}

func NewManager(agents map[string]config.AgentConfig, logger *slog.Logger, project ProjectContext) *Manager {
return NewManagerWithOptions(agents, logger, project)
}
Expand Down
46 changes: 46 additions & 0 deletions src/crux/agent/manager_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package agent

// Manager construction options and the persisted UID-map path they select.
// Kept out of manager.go so that file stays under the crux file-size ratchet.

type ManagerOption func(*managerOptions)

type managerOptions struct {
uidMapPath string
uidMapPathSet bool
sharedPool SharedSessionPool
}

// WithUIDMapPath points a manager at a specific persisted UID map. Production
// callers keep the default UIDMapPath; tests can inject a hermetic path.
func WithUIDMapPath(path string) ManagerOption {
return func(opts *managerOptions) {
opts.uidMapPath = path
opts.uidMapPathSet = true
}
}

// WithSharedSessionPool opts a manager into a Hub-coordinated live CLI slot.
// Every Hive retains separate sessions and tenant data; the lease only limits
// how many CLI sessions across the participating Hives remain live.
func WithSharedSessionPool(pool SharedSessionPool) ManagerOption {
return func(opts *managerOptions) { opts.sharedPool = pool }
}

func (m *Manager) effectiveUIDMapPath() string {
if m.uidMapPath != "" {
return m.uidMapPath
}
return UIDMapPath
}

func (m *Manager) saveUIDMap() {
if m.uidMap == nil {
return
}
path := m.effectiveUIDMapPath()
_ = m.uidMap.Save(path)
if path == PersistedUIDMapPath && UIDMapPath != "" && UIDMapPath != path {
_ = m.uidMap.Save(UIDMapPath)
}
}
Loading