Update release.contract type from string to JsonType

This commit is contained in:
myarmolinsky 2024-09-17 07:11:05 -04:00
parent 19be0fec1a
commit 61af57acc9
6 changed files with 18 additions and 12 deletions

View File

@ -127,7 +127,7 @@ export const createRelease = async function (
composition: Composition,
draft: boolean,
semver: string | undefined,
contract: string | undefined,
contract: import('@balena/compose/dist/release/models').ReleaseModel['contract'],
): Promise<Release> {
const _ = require('lodash') as typeof import('lodash');
const crypto = require('crypto') as typeof import('crypto');

View File

@ -1404,7 +1404,7 @@ export async function deployProject(
composition,
isDraft,
contract?.version,
contract ? JSON.stringify(contract) : undefined,
contract,
),
);
const { client: pineClient, release, serviceImages } = $release;
@ -1500,7 +1500,9 @@ export function createRunLoop(tick: (...args: any[]) => void) {
async function getContractContent(
filePath: string,
): Promise<Dictionary<any> | undefined> {
): Promise<
import('@balena/compose/dist/release/models').ReleaseModel['contract']
> {
let fileContentAsString;
try {
fileContentAsString = await fs.readFile(filePath, 'utf8');

View File

@ -208,9 +208,8 @@ export async function validateSecureBootOptionAndWarn(
throw new ExpectedError(`Error: No ${version} release for ${slug}`);
}
const contract = osRelease.contract ? JSON.parse(osRelease.contract) : null;
if (
contract?.provides.some((entry: Dictionary<string>) => {
osRelease.contract?.provides.some((entry: Dictionary<string>) => {
return entry.type === 'sw.feature' && entry.slug === 'secureboot';
})
) {

View File

@ -93,7 +93,7 @@ export class DeviceAPI {
);
}
public async getTargetState(): Promise<any> {
public async getTargetState() {
const url = this.getUrlForAction('getTargetState');
return DeviceAPI.promisifiedRequest(

View File

@ -636,6 +636,7 @@ export function generateTargetState(
services[idx] = {
...defaults,
...opts,
// TODO: is this affected by the `contract` typing change?
...(contract != null ? { contract } : {}),
...{
imageId: idx,

View File

@ -183,9 +183,11 @@ describe('balena deploy', function () {
api.expectPostRelease({
inspectRequest: (_uri: string, requestBody: nock.Body) => {
const body = requestBody.valueOf() as Partial<ReleaseRequest>;
expect(body.contract).to.be.equal(
'{"name":"testContract","type":"sw.application","version":"1.5.2"}',
);
expect(body.contract).to.deep.equal({
name: 'testContract',
type: 'sw.application',
version: '1.5.2',
});
expect(body.is_final).to.be.true;
},
});
@ -232,9 +234,11 @@ describe('balena deploy', function () {
api.expectPostRelease({
inspectRequest: (_uri: string, requestBody: nock.Body) => {
const body = requestBody.valueOf() as Partial<ReleaseRequest>;
expect(body.contract).to.be.equal(
'{"name":"testContract","type":"sw.application","version":"1.5.2"}',
);
expect(body.contract).to.deep.equal({
name: 'testContract',
type: 'sw.application',
version: '1.5.2',
});
expect(body.semver).to.be.equal('1.5.2');
expect(body.is_final).to.be.false;
},