Skip to content

Commit bc0069f

Browse files
committed
fix: align template tracking assignments
1 parent b8ba992 commit bc0069f

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

inc/Cli/Commands/AgentBundleCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ protected function classified_installed_artifacts( array $agent, array $installe
991991
if ( ! is_array( $record ) ) {
992992
continue;
993993
}
994-
$key = AgentBundleArtifactExtensions::artifact_key( (string) ( $record['artifact_type'] ?? '' ), (string) ( $record['artifact_id'] ?? '' ) );
995-
$current_hash = isset( $current[ $key ] ) ? AgentBundleArtifactHasher::hash( $current[ $key ]['payload'] ?? null ) : null;
994+
$key = AgentBundleArtifactExtensions::artifact_key( (string) ( $record['artifact_type'] ?? '' ), (string) ( $record['artifact_id'] ?? '' ) );
995+
$current_hash = isset( $current[ $key ] ) ? AgentBundleArtifactHasher::hash( $current[ $key ]['payload'] ?? null ) : null;
996996
$record['current_hash'] = $current_hash;
997997
$record['status'] = AgentBundleArtifactStatus::classify( (string) ( $record['installed_hash'] ?? '' ), $current_hash );
998998
$classified[] = $record;

inc/Core/Agents/AgentBundler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,10 @@ public function import( array $bundle, ?string $new_slug = null, int $owner_id =
536536
);
537537
$template_metadata = AgentTemplateMetadata::from_bundle_array( $bundle )->to_array();
538538
unset( $template_metadata['installed_hashes'] );
539-
$bundle_metadata = array_merge( $template_metadata, $bundle_metadata );
540-
$is_portable_bundle = ! empty( $bundle['bundle_slug'] ) || $this->bundle_has_portable_artifacts( $bundle );
541-
$reconcile_runtime = ! empty( $options['reconcile_runtime'] );
542-
$is_upgrade = ! empty( $options['is_upgrade'] );
539+
$bundle_metadata = array_merge( $template_metadata, $bundle_metadata );
540+
$is_portable_bundle = ! empty( $bundle['bundle_slug'] ) || $this->bundle_has_portable_artifacts( $bundle );
541+
$reconcile_runtime = ! empty( $options['reconcile_runtime'] );
542+
$is_upgrade = ! empty( $options['is_upgrade'] );
543543

544544
// Check for slug collision.
545545
// On install: existing slug + (renamed-to-collision OR non-portable bundle) is a hard error.

inc/Engine/Bundle/AgentBundleUpgradeActionHandlers.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,30 @@ private static function record_applied_artifact( array $artifact, int $agent_id,
206206
return new \WP_Error( 'datamachine_bundle_agent_missing', sprintf( 'Agent ID %d was not found.', $agent_id ) );
207207
}
208208

209-
$config = is_array( $agent['agent_config'] ?? null ) ? $agent['agent_config'] : array();
210-
$bundle = is_array( $context['bundle'] ?? null ) ? $context['bundle'] : array();
211-
$bundle_slug = (string) ( $bundle['bundle_slug'] ?? $config['datamachine_bundle']['bundle_slug'] ?? '' );
212-
$version = (string) ( $bundle['bundle_version'] ?? $config['datamachine_bundle']['bundle_version'] ?? '' );
209+
$config = is_array( $agent['agent_config'] ?? null ) ? $agent['agent_config'] : array();
210+
$bundle = is_array( $context['bundle'] ?? null ) ? $context['bundle'] : array();
211+
$bundle_slug = (string) ( $bundle['bundle_slug'] ?? $config['datamachine_bundle']['bundle_slug'] ?? '' );
212+
$version = (string) ( $bundle['bundle_version'] ?? $config['datamachine_bundle']['bundle_version'] ?? '' );
213213
$template_slug = (string) ( $bundle['template_slug'] ?? $config['datamachine_bundle']['template_slug'] ?? $bundle_slug );
214214
$template_version = (string) ( $bundle['template_version'] ?? $config['datamachine_bundle']['template_version'] ?? $version );
215215
$source_ref = (string) ( $bundle['source_ref'] ?? $config['datamachine_bundle']['source_ref'] ?? '' );
216216
$source_revision = (string) ( $bundle['source_revision'] ?? $config['datamachine_bundle']['source_revision'] ?? '' );
217-
$type = (string) ( $artifact['artifact_type'] ?? '' );
218-
$id = (string) ( $artifact['artifact_id'] ?? '' );
219-
$payload = $artifact['payload'] ?? null;
220-
$hash = AgentBundleArtifactHasher::hash( $payload );
221-
$now = gmdate( 'c' );
217+
$type = (string) ( $artifact['artifact_type'] ?? '' );
218+
$id = (string) ( $artifact['artifact_id'] ?? '' );
219+
$payload = $artifact['payload'] ?? null;
220+
$hash = AgentBundleArtifactHasher::hash( $payload );
221+
$now = gmdate( 'c' );
222222

223223
if ( '' === $bundle_slug || '' === $type || '' === $id ) {
224224
return new \WP_Error( 'datamachine_bundle_registry_incomplete', 'Bundle artifact registry metadata is incomplete.' );
225225
}
226226

227-
$config['datamachine_bundle']['bundle_slug'] = $bundle_slug;
228-
$config['datamachine_bundle']['bundle_version'] = $version;
227+
$config['datamachine_bundle']['bundle_slug'] = $bundle_slug;
228+
$config['datamachine_bundle']['bundle_version'] = $version;
229229
$config['datamachine_bundle']['template_slug'] = $template_slug;
230230
$config['datamachine_bundle']['template_version'] = $template_version;
231-
$config['datamachine_bundle']['source_ref'] = $source_ref;
232-
$config['datamachine_bundle']['source_revision'] = $source_revision;
231+
$config['datamachine_bundle']['source_ref'] = $source_ref;
232+
$config['datamachine_bundle']['source_revision'] = $source_revision;
233233
$config['datamachine_bundle']['artifacts'][ AgentBundleArtifactExtensions::artifact_key( $type, $id ) ] = array(
234234
'bundle_slug' => $bundle_slug,
235235
'bundle_version' => $version,

inc/Engine/Bundle/AgentTemplateMetadata.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public static function from_manifest( AgentBundleManifest $manifest, string $tem
7474
}
7575

7676
public static function from_bundle_array( array $bundle, array $installed_hashes = array() ): self {
77-
$bundle_slug = (string) ( $bundle['bundle_slug'] ?? ( $bundle['agent']['agent_slug'] ?? 'bundle' ) );
78-
$bundle_version = (string) ( $bundle['bundle_version'] ?? '1' );
79-
$template = is_array( $bundle['template'] ?? null ) ? $bundle['template'] : array();
80-
$template_meta = is_array( $bundle['template_metadata'] ?? null ) ? $bundle['template_metadata'] : array();
81-
$template_slug = (string) ( $bundle['template_slug'] ?? $template['slug'] ?? $template_meta['template_slug'] ?? $bundle_slug );
77+
$bundle_slug = (string) ( $bundle['bundle_slug'] ?? ( $bundle['agent']['agent_slug'] ?? 'bundle' ) );
78+
$bundle_version = (string) ( $bundle['bundle_version'] ?? '1' );
79+
$template = is_array( $bundle['template'] ?? null ) ? $bundle['template'] : array();
80+
$template_meta = is_array( $bundle['template_metadata'] ?? null ) ? $bundle['template_metadata'] : array();
81+
$template_slug = (string) ( $bundle['template_slug'] ?? $template['slug'] ?? $template_meta['template_slug'] ?? $bundle_slug );
8282
$template_version = (string) ( $bundle['template_version'] ?? $template['version'] ?? $template_meta['template_version'] ?? $bundle_version );
8383

8484
return new self(

0 commit comments

Comments
 (0)