runtime+test: fix close-{input,output}-port and add tests.