Skip to content

Commit

Permalink
Rename contract capabilities property to provides
Browse files Browse the repository at this point in the history
This lines up better with the original specification and how contracts
are being used by the OS

Change-type: minor
  • Loading branch information
pipex committed Jan 15, 2025
1 parent 5e969d5 commit d2b2177
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ export default class Contract {
// the list of hashes we should check against.
const match = matches(omit(matcher.raw.data, ['slug', 'version']));
const versionMatch = matcher.raw.data.version;
if (contract.raw.capabilities) {
for (const capability of contract.raw.capabilities) {
if (contract.raw.provides) {
for (const capability of contract.raw.provides) {
if (match(capability)) {
if (versionMatch) {
if (valid(capability.version) && validRange(versionMatch)) {
Expand Down Expand Up @@ -1290,6 +1290,7 @@ export default class Contract {
for (const conjunct of conjuncts) {
// (3-4) stop looking if an unsatisfied requirement is found
if (!this.isRequirementSatisfied(conjunct, options)) {
console.log('NOT SATISFIED', JSON.stringify(conjunct));
return false;
}
}
Expand Down
54 changes: 54 additions & 0 deletions tests/contract/satisfies-child-contract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,60 @@ describe('Contract satisfiesChildContract', () => {
).to.be.true;
});

it('should return true given two fulfilled requirements from a context declaring capabilities with `provides`', () => {
const container = new Contract({
type: 'foo',
slug: 'bar',
});

const contract1 = new Contract({
type: 'meta.context',
slug: 'test',
provides: [
{
type: 'sw.os',
slug: 'debian',
version: 'wheezy',
},
{
type: 'arch.sw',
slug: 'amd64',
version: '1',
},
],
});

container.addChild(contract1);

expect(
container.satisfiesChildContract(
new Contract({
name: 'Node.js',
slug: 'nodejs',
type: 'sw.stack',
requires: [
{
slug: 'debian',
type: 'sw.os',
},
{
or: [
{
slug: 'amd64',
type: 'arch.sw',
},
{
slug: 'i386',
type: 'arch.sw',
},
],
},
],
}),
),
).to.be.true;
});

it('should return false given one unfulfilled requirement from a context with a composite contract', () => {
const container = new Contract({
type: 'foo',
Expand Down

0 comments on commit d2b2177

Please sign in to comment.