agent: Fix assertion in cockpit_resource_finalize()

The close virtual method was not being called if the transport
closed before the channel.

Add a test which double checks this problem.

Fixes #1104